I use ggplot2
and knitr
发布带有右侧图例的散点图。图例包含在纵横比中,因此破坏了绘图的“方形”,如图所示默认主题 https://github.com/hadley/ggplot2/wiki/themes。当图例文本变得比“a”和“b”长一点时,图形就会变成“长矩形”而不是“正方形”。
我想保持图表“平方”,因此想从我的纵横比中排除图例ggplot2
图表。我的.Rprofile
有以下信息强制ggplot2
生成带有更大文本和轴标题周围更多空间的低色图表:
theme_set(theme_bw(16))
theme_update(
axis.title.y = element_text(angle = 90, vjust = -.25),
axis.title.x = element_text(vjust = -1),
plot.margin = unit(c(1,1,1,1), "cm")
)
我可以在此处添加任何内容以从宽高比中排除图例吗?操纵与coord_equal
and coord_fixed
到目前为止都失败了,同样fig.width
and fig.height
选项。感谢您的帮助!
Edit:删除了工作示例,下面用完整的示例代码回答了问题(很抱歉延迟批准答案)。
Setting coord_fixed()
应该做的伎俩:
library(ggplot2)
library(gridExtra) ## for grid.arrange()
## Create some data with one longer label
cars <- transform(mtcars,
cyl = factor(cyl, labels=c("4","6","8 is big")))
## Compute ratio needed to make the figure square
## (For a taller narrow plot, multiply ratio by number > 1;
## for a squatter plot, multiply it by number in the interval (0,1))
ratio <- with(cars, diff(range(mpg))/diff(range(wt)))
## Make plots with and without a legend
a <- ggplot(cars, aes(mpg, wt)) +
geom_point() + coord_fixed(ratio=ratio)
b <- ggplot(cars, aes(mpg, wt, color=cyl)) +
geom_point() + coord_fixed(ratio=ratio)
## Plot them to confirm that coord_fixed does fix the aspect ratio
grid.arrange(a,b, ncol=2)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)