[英]How to make entropy chart in ggplot i.e. stacked and filled x-axis?
I'm trying to turn this data 我正试图把这些数据
data = data.frame(group = c("a", "b", "c", "d"),
proportion = c(0.101787806629625, 0.578844918169105, 0.11046225951544, 0.20890501568583),
entropy = c(0.521351652432232, 0.519605602533547, 0.443798118049615, 0.495838610457753 ))
group proportion entropy
a 0.1017878 0.5213517
b 0.5788449 0.5196056
c 0.1104623 0.4437981
d 0.2089050 0.4958386
into an entropy chart , which looks something like this 变成一个熵图 ,看起来像这样
My attempt only got me so far 到目前为止,我的尝试才使我
ggplot(data, aes(x=as.factor(proportion), y=entropy)) +
geom_bar(stat="identity", aes(width=proportion))
Can it be done? 能做到吗
What about something like this 那这样的事呢
#transform data
data<-data[order(data$entropy),]
data$cp<-cumsum(data$proportion)
#plot
ggplot(data, aes(xmin=cp-proportion, xmax=cp, ymin=0, ymax=entropy)) +
geom_rect(aes(fill=group)) + xlab("proportion") + ylab("entropy")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.