df2 <- iris[c(5,1)]
df3 <- aggregate(df2$Sepal.Length, list(df2$Species), mean)
names(df3) <- c("x","y")
ggplot(df3, aes(x,y)) +
geom_bar(aes(fill=x),stat="identity") +
theme(axis.ticks=element_blank(), axis.text.x=element_blank())
我已经成功地从此图中删除了轴刻度线和标签。我试图摆脱酒吧下方的空白灰色空间。零应该是图表的下限。我一直在寻找一种调整功能来向下拉条或切断底部灰色部分,但没有成功。希望 ggplots 不会与下面的额外空间硬连线。
将以下元素添加到您的代码中(受 this Q & A 启发):
theme_classic()
scale_x_discrete(expand=c(0,0))
scale_y_continuous(expand=c(0,0))
除了 theme_classic()
,您还可以使用 theme_bw()
,它会在绘图中添加水平线和垂直线。
您的代码应该如下所示:
ggplot(df3, aes(x,y)) +
geom_bar(aes(fill=x),stat="identity") +
scale_x_discrete(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
theme_classic() +
theme(axis.ticks=element_blank(), axis.text.x=element_blank())
这给出: