R How to visualize this categorical percentage data?

995 views Asked by At

I have the following matrix data, 3 Forms of policies by loss causes in the columns:

test=as.data.frame(matrix(c(74,10,4,4,2,6,57,19,4,8,2,10,54,19,6,8,2,11),nrow=3,byrow=T))
names(test) <- c("Wind","Water","Fire","Theft","Liab","OtherPD")
row.names(test)  <- c("FormA","FormB","FormC")

And data looks like this:

      Wind Water Fire Theft Liab OtherPD
FormA   74    10    4     4    2       6
FormB   57    19    4     8    2      10
FormC   54    19    6     8    2      11

Each row shows the percentage of losses within a Form that is attributed to the cause. For instance, 74% of losses in FormA is due to wind losses. Each row will add up to 100.

Question: please suggest a way to visualize this other than pie charts for each row such as:

pie(unlist(test[1,]),labels=c("Wind","Water","Fire","Theft","Liab","OtherPD"),main= "FormA")

A comment on the percentages is that although some numbers may look small, their corresponding underlying dollar amounts are still significant and credible. A more prominent insight I'd like to convey through visualization is how each policy forms compare against each other in losses due to all these different perils, and especially the "smaller" ones, not to be blinded by the fact that FormA has a dominant proportion of wind losses.

1

There are 1 answers

3
jburkhardt On BEST ANSWER

I suggest that you restructure the data. ggplot has some nice charts.

#restructure data
library(reshape2)
data <- melt(test)
data$Form <- c("FormA","FormB","FormC")
#plot with ggplot2
library(ggplot2)
ggplot(data, aes(variable, value)) + geom_bar(stat="identity") + facet_wrap(~ Form)
ggplot(data, aes(variable, value)) + geom_point() + facet_wrap(~ Form)
ggplot(data, aes(variable, value,colour=Form, group=Form)) + geom_point()