简体   繁体   English

R如何可视化此分类百分比数据?

[英]R How to visualize this categorical percentage data?

I have the following matrix data, 3 Forms of policies by loss causes in the columns: 我有以下矩阵数据,各栏中按损失原因列出的3种保单形式:

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. 例如,FormA中74%的损失是由于风的损失。 Each row will add up to 100. 每行总计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. 我想通过可视化传达的一个更重要的见解是,由于所有这些不同的风险,尤其是“较小”的风险,每种保单形式在损失方面如何相互比较,而不被FormA具有主导地位的事实所蒙蔽wind损比例。

I suggest that you restructure the data. 我建议您重组数据。 ggplot has some nice charts. ggplot有一些不错的图表。

#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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM