0

我是 R 的初学者,我需要从下面的数据中重建我的马赛克图。

情节不是我想象的那样,标签全错了,我不想显示列联表。我尝试了不同的线条来更改标签,但它不断给我更多扭曲的情节。我想编辑它看起来像例子中的情节。

我想将灾难作为 x 轴,将国家(在 ISO 列下)放在 y 轴上。我还想描述每个盒子上的数字。如何更正此脚本或使用 ggplot2 或 vcd 或 MASS 包编写更好的脚本?

数据

ISO Flood   Storm   Cyclone Heavy rain  Drought Landslides
AGO 5000    NA  NA  NA  NA  NA
BDI 500 500 NA  800 NA  3600
BEN 260 NA  NA  NA  NA  NA
BFA 6248    NA  NA  NA  2500    NA
BWA 833 NA  NA  NA  NA  NA
CAF 5000    4000    NA  644 NA  NA
CIV 987 NA  NA  NA  NA  4000
CMR 655 NA  NA  NA  NA  520
COD 300 50  400 254 NA  40

代码

getwd()
"G:/"
trial_one <- read.csv("trial_one.csv", TRUE, sep = ",",
     na.strings = TRUE)
mosaicplot( trial_one, main = "Enviromental changes by Country",
      sub = "SSA",
      xlab = "Mosaic plot",
     ylab = "Extreme_changes",
     las = 1,
     color = "skyblue2",
     border = "chocolate")
#mosaicplot(events)

structure(list(ï..ISO = structure(1:9, .Label = c("AGO", "BDI", "BEN", "BFA", "BWA", "CAF", "CIV", "CMR", "COD"), class = "factor"), Flood = structure(c(1L, 5L, 3L, 9L, 2L, 8L, 6L, 4L, 7L), .Label = c("5,000", "833", "260", "655", "500", "987", "300", "5,000", "6,248"), class = "factor"), Storm = structure(c(4L, 2L, 4L, 4L, 4L, 1L, 4L, 4L, 3L), .Label = c("4,000", "500", "50", "NA"), class = "factor"), Cyclone = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L), .Label = c("400", "NA" ), class = "factor"), Heavy.rain = structure(c(4L, 3L, 4L, 4L, 4L, 1L, 4L, 4L, 2L), .Label = c("644", "254", "800", "NA"), class = "factor"), Drought = structure(c(2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("2,500", "NA" ), class = "factor"), Landslides = structure(c(5L, 4L, 5L, 5L, 5L, 5L, 1L, 2L, 3L), .Label = c("4,000", "520", "40", "3600", "NA"), class = "factor")), class = "data.frame", row.names = c(NA, -9L))

4

0 回答 0