I am a beginner in R and I need to reconstruct my mosaic plot from the data below.
The plot isn't quite what I imagined, the labeling is all wrong and I don't want to display the contingency table. I tried different lines to change the label but it kept giving me more distorted plots. I would like to edit it to look like the plot on example.
I want to put the disasters as the x-axis and the countries (under ISO column) on the y-axis. I would also like to describe the numbers on each box. How to correct this script or write a better one with ggplot2 or vcd or MASS packages?
Data
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
Code
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))

