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())

I have successfully removed axis tick marks and labels from this plot. I am trying to get rid of the blank grey space underneath the bars. Zero should be the lower bound for the chart. I've been searching unsuccessfully for an adjustment function to either pull the bars down or to cut off the bottom grey portion. The hope is that ggplots are not hardwired with the extra space underneath.
Add the following elements to your code (inspired by this Q & A):
theme_classic()
scale_x_discrete(expand=c(0,0))
scale_y_continuous(expand=c(0,0))
Instead of theme_classic(), you can also use theme_bw() which will add horizontal and vertical lines to the plot.
You code should then look like this:
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())
this gives:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With