我正在尝试将条形之间的距离缩小得更窄,但是, position_dodge 似乎在调整条形之间的距离方面不起作用。
下面是我的代码示例,其中有两个宽度不同的输出,一个为 0.7,一个为 5,但条形之间的宽度不受影响......:
library(ggplot2)
library(grid)
library(ggthemes)
library(scales)
library(gridExtra)
variables = c('a','b','c','d','e')
values = c(0.2,0.4,0.6,0.8,1.0)
std = c(0.05,0.06,0.03,0.08,0.09)
Data = data.frame(variables, values, std)
f3 = ggplot(data = Data, aes(x = variables, y = values, group = variables) ) +
geom_bar(stat='identity',width=0.6,position=position_dodge(width = 0.7),fill=c('#FF7F0E','#2CA02C','#D62728', '#00008B', '#B23AEE')) +
coord_flip() +
geom_errorbar(aes(ymin=values-std, ymax=values+std),
width=.2,size=0.3) +
scale_y_continuous("Variable Importance", expand = c(0,0),limits = c(0, 1.1), breaks=seq(0, 1.1, by = 0.1)) + # rescale Y axis slightly
scale_x_discrete("Variables", limits = c('a','b',"c","d","e" )) +
theme_bw() + # make the theme black-and-white rather than grey (do this before font changes, or it overrides them)
theme(
line = element_line(size=0.3),
plot.title = element_blank(), # use theme_get() to see available options
axis.title.x = element_text(family='sans',size=13),
axis.title.y = element_text(family='sans',size=13, angle=90),
axis.text.x = element_text(family='sans',vjust=0.4,size=11),
axis.text.y = element_text(family='sans',size=11),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
legend.position = 'none', # manually position the legend (numbers being from 0,0 at bottom left of whole plot to 1,1 at top right)
legend.title = element_blank(), # switch off the legend title
legend.text = element_blank(),
legend.key.size = unit(1.5, "lines"),
legend.key = element_blank(), # switch off the rectangle around symbols in the legend
panel.border=element_blank(),
axis.line=element_line(size=0.3)
)
plot(f3)
任何帮助将不胜感激!谢谢,