Reputation: 617
How could I change the distance from the bar to the Y axis in ggplot?
k <- c("a","b","c","d","e","f")
j <- c(3,500,1000,1,2,6)
df <- data.frame(k,j)
ggplot(df, aes(y=reorder(k, -j), x=j))+
geom_col(fill="#70A2E7", width = 0.85)+
theme_bw(10)+
geom_text(aes(label=j), size=3.5, angle= 0, hjust=-0.05)
Upvotes: 2
Views: 1190
Reputation: 39585
You can play with expand
in scale_x_continuous()
:
library(ggplot2)
#Data
k <- c("a","b","c","d","e","f")
j <- c(3,500,1000,1,2,6)
df <- data.frame(k,j)
#Plot
ggplot(df, aes(y=reorder(k, -j), x=j))+
geom_col(fill="#70A2E7", width = 0.85)+
theme_bw(10)+
geom_text(aes(label=j), size=3.5, angle= 0, hjust=-0.05)+
scale_x_continuous(expand = c(0,0),limits = c(NA,1100))
Output:
Upvotes: 2