此问题与:ggplot in function not working despite aes_string in R
有关> dput(df1)
structure(list(firstvar = c("a1", "a2", "a3"), secondvar = c(25L,
50L, 75L)), .Names = c("firstvar", "secondvar"), class = "data.frame", row.names = c(NA,
-3L))
> df1
firstvar secondvar
1 a1 25
2 a2 50
3 a3 75
myplot = function(ddf){
ggplot(ddf) +
geom_bar(aes_string(1, names(ddf)[2], fill=names(ddf)[1]), stat="identity")+
geom_text(aes_string(x=1, y=cumsum((ddf)[2]), label=names(ddf)[2]))
}
myplot(df1)
情节正在运行,但我想在x轴上没有文字(因为1只是为了在x轴上有一个点;它并不代表数据中的任何内容)。放置任何字符,包括“”空白字符会产生错误或破坏图形。如何在此处删除x轴文本?
答案 0 :(得分:1)
您可以将axis.text.x
theme()
设置为element_blank().
来删除轴文字
myplot = function(ddf){
ggplot(ddf) +
geom_bar(aes_string(1, names(ddf)[2], fill=names(ddf)[1]), stat="identity")+
geom_text(aes_string(x=1, y=cumsum((ddf)[2]), label=names(ddf)[2]))+
theme(axis.text.x=element_blank())
}
myplot(df1)