0

我在使用 ggplot 时遇到问题。我的代码应该使用 (plot.background = element_rect(color="black") 给我一个围绕整个情节的框架。但是我只得到四行中的三行。关于如何从四行中获得四行的任何想法?

我有这个主题:

theme.plot.bar <- function(){

 theme(
text                   = element_text(family = "sans", face = "plain", colour = "black", size = 12, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9),
axis.text.x            = element_text(size = 13, colour = "black"),
axis.text.y            = element_text(size = 11, colour = "black"),
strip.text             = element_text(size = rel(0.8)),
axis.text.x            = element_text(vjust = 1),
axis.text.y            = element_text(hjust = 1), 
axis.ticks             = element_blank(),
axis.title.x           = element_text(), 
axis.title.y           = element_text(angle = 90),
panel.background       = element_rect(fill = NA ,colour = NA),
panel.grid.major.x     = element_blank(),
panel.grid.minor       = element_blank(),
panel.grid.major.y     = element_line(colour = "black", linetype= "dotted", size =0.6),
strip.text.x           = element_text(),
strip.text.y           = element_text(angle = -90),
plot.background        = element_rect(colour = "black", size = 0.5, linetype= 1, fill="white"), # Kant i højre side kommer ikke med hvis den sættes?
plot.margin            = unit(c(0, 1, 0, 0), "cm"),
complete               = FALSE)

}

这给了我这个带有ggplot的输出:

在此处输入图像描述

编辑:将 plot.margin 更改为 3 cm: 在此处输入图像描述

编辑 2:根据要求使用会话信息和 ggplot-code 注意:将所有绘图边距设置为 2 inhes 时它仍然不起作用。我用.png

sessionInfo() R 版本 2.15.3 (2013-03-01) 平台:x86_64-w64-mingw32/x64 (64-bit)

x              <- factor(pol$job_komp_v2)
df             <- as.data.frame(na.omit(x))
names(df)      <- "v1"
farve          <- rgb(144,26,30, maxColorValue =255)

r <- ggplot(df,aes(x=v1)) +
geom_bar(aes(y = (..count..)/sum(..count..)), 
fill=farve, width=0.35) + 
scale_y_continuous(labels = percent, "", limits=c(0,1), breaks= c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)) +
scale_x_discrete(name= "") +
theme.plot.bar()
r
4

0 回答 0