[英]R bar plot: how to set specified number in y axis but do not change the distance between numbers in R
[英]How to change the distance between the bar and the Y axis in R
如何在 ggplot 中更改從條形到 Y 軸的距離?
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)
您可以在scale_x_continuous()
中使用expand
:
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:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.