admin管理员组文章数量:1410682
I followed the code on this page to create balloon plots with ggballoonplot() using facet.by. I wanted to add an x axis title, so I followed what was recommended in the question asked here to which described how to add an axis label to a balloon plot.
library(ggplot2)
df <- as.data.frame(HairEyeColor)
p<-ggballoonplot(df, x = "Hair", y = "Eye", size = "Freq",
fill = "Freq", facet.by = "Sex",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C")+
xlab("Group")
Which produces this plot, missing the xlab that I thought I had specified.
I also tried to assign an xlab as follows, but it also didn't work as planned (produces the same plot as shown above).
p2<-ggballoonplot(df, x = "Hair", y = "Eye", size = "Freq",
fill = "Freq", facet.by = "Sex",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C")+
labs(x = "Group")
Any ideas? As per the SO post I linked to, someone suggested it might be a print/rendering settings issue, but they didn't offer any suggestions on how to pursue that possibility and resolve the issue. Thanks!
I followed the code on this page to create balloon plots with ggballoonplot() using facet.by. I wanted to add an x axis title, so I followed what was recommended in the question asked here to which described how to add an axis label to a balloon plot.
library(ggplot2)
df <- as.data.frame(HairEyeColor)
p<-ggballoonplot(df, x = "Hair", y = "Eye", size = "Freq",
fill = "Freq", facet.by = "Sex",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C")+
xlab("Group")
Which produces this plot, missing the xlab that I thought I had specified.
I also tried to assign an xlab as follows, but it also didn't work as planned (produces the same plot as shown above).
p2<-ggballoonplot(df, x = "Hair", y = "Eye", size = "Freq",
fill = "Freq", facet.by = "Sex",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C")+
labs(x = "Group")
Any ideas? As per the SO post I linked to, someone suggested it might be a print/rendering settings issue, but they didn't offer any suggestions on how to pursue that possibility and resolve the issue. Thanks!
Share Improve this question edited Mar 6 at 17:17 stefan 127k6 gold badges38 silver badges76 bronze badges Recognized by R Language Collective asked Mar 6 at 16:58 DoctorSpruceDoctorSpruce 1591 silver badge8 bronze badges1 Answer
Reset to default 1The issue is that under the hood ggballoonplot
removes the axis title via theme()
, i.e. axis.title.x = element_blank()
. Hence, adding a title via xlab()
or labs()
has no effect. Instead you have to override the theme()
element, too, using axis.title.x = element_text()
:
library(ggplot2)
library(ggpubr)
df <- as.data.frame(HairEyeColor)
ggballoonplot(df,
x = "Hair", y = "Eye", size = "Freq",
fill = "Freq", facet.by = "Sex",
ggtheme = theme_bw()
) +
scale_fill_viridis_c(option = "C") +
xlab("Group") +
theme(axis.title.x = element_text())
本文标签: rAdding a X axis title to faceted ggballoonplotStack Overflow
版权声明:本文标题:r - Adding a X axis title to faceted ggballoonplot - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744960724a2634636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论