R 多面减淡条形图上的geom_文本标签
我使用ggplot2创建了下面的图像。我想探索将数据按主题(国外、经济等)作为facet_wrap的各个方面来查看。我可以重组我想要的任何东西,除了我不能再把标签(73(1.02%)、67(.93%)等)放回酒吧。如何绘制标签 这是我的密码:R 多面减淡条形图上的geom_文本标签,r,ggplot2,R,Ggplot2,我使用ggplot2创建了下面的图像。我想探索将数据按主题(国外、经济等)作为facet_wrap的各个方面来查看。我可以重组我想要的任何东西,除了我不能再把标签(73(1.02%)、67(.93%)等)放回酒吧。如何绘制标签 这是我的密码: dat3 <- structure(list(grouping.var = structure(c(1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L), clas
dat3 <- structure(list(grouping.var = structure(c(1L, 3L, 1L, 3L, 1L,
3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L), class = "factor", .Label = c("BIDEN",
"RADDATZ", "RYAN")), word.count = c(7240, 7153, 7240, 7153, 7240,
7153, 7240, 7153, 7240, 7153, 7240, 7153, 7240, 7153, 7240, 7153
), variable = structure(c(4L, 4L, 2L, 2L, 1L, 1L, 5L, 5L, 3L,
3L, 7L, 7L, 6L, 6L, 8L, 8L), .Label = c("foreign", "economic",
"rebublican_people", "health", "democratic_people", "romney",
"obama_any_name", "obama_by_name"), class = "factor"), value = c(29,
36, 27, 47, 67, 73, 13, 28, 45, 24, 13, 20, 26, 21, 1, 14), labs = c("29(.0040)",
"36(.0050)", "27(.0037)", "47(.0066)", "67(.0093)", "73(.0102)",
"13(.0018)", "28(.0039)", "45(.0062)", "24(.0034)", "13(.0018)",
"20(.0028)", "26(.0036)", "21(.0029)", "1(.0001)", "14(.0020)"
), loc = c(22.5, 29.5, 20.5, 40.5, 60.5, 65.75, 6.5, 21.5, 38.5,
17.5, 6.5, 13.5, 19.5, 14.5, 7, 7.5), cols = c("black", "white",
"white", "white", "white", "white", "white", "white", "white",
"white", "white", "white", "white", "white", "white", "white"
)), .Names = c("grouping.var", "word.count", "variable", "value",
"labs", "loc", "cols"), row.names = c(NA, -16L), class = "data.frame")
ggplot(dat3, aes(x=variable, y=value, fill=grouping.var)) +
geom_bar(position="dodge", stat="identity") +
coord_flip() + theme_bw() +
theme(legend.position="top", legend.background = element_rect(color="white"),
panel.grid.major=element_blank(),panel.grid.minor=element_blank(),
legend.title=element_blank(), axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
ylab("") + xlab("") + facet_wrap(~variable, ncol=2, scales = "free_x") +
scale_fill_manual(values=c("#0000FF", "#FF0000"),
guide = guide_legend(reverse=TRUE))
geom_text(aes(label = labs, y = loc, x = variable),
size = 5, position = position_dodge(width=0.9), color=dat3$cols)
dat3我去掉了color=dat3$cols
,它似乎起作用了
ggplot(dat3, aes(x=variable, y=value, fill=grouping.var)) +
geom_bar(position="dodge", stat="identity") +
coord_flip() + theme_bw() +
theme(legend.position="top", legend.background = element_rect(color="white"),
panel.grid.major=element_blank(),panel.grid.minor=element_blank(),
legend.title=element_blank(), axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
ylab("") + xlab("") + facet_wrap(~variable, ncol=2, scales = "free_x") +
scale_fill_manual(values=c("#0000FF", "#FF0000"),
guide = guide_legend(reverse=TRUE))+
geom_text(aes(label = labs, y = loc, x = variable),
size = 5, position = position_dodge(width=0.9))
我遇到了一个类似的问题,不是真正的bug。但没有很好的记录
喜欢你的那一套吗
“我去掉了color=dat3$cols
,它似乎起作用了”
解决方案是在任何可以解释aes的内容中详细指定所有颜色值(color=foo)
在我的例子中,我在ggplot()和geom_text()中调用了两个aes()
1) ggplot(dat_foo,aes(x=xfoo_i,y=yfoo,color=colorfoo,group=groupfoo))
2) geom\u文本(数据=标签数据,aes(x=xfoo,y=yfoo,标签=标签foo,颜色=NULL)
很有意思。感谢开发人员版本,这没有什么区别。+1这很有意思。值得在github页面上提出一个问题。卸载开发人员版本后,现在尝试重新安装开发人员版本以重新创建错误,我似乎无法重新安装开发人员版本。我将等待发布问题,直到可以重新安装"0.9.2.99"