删除R中的空白(即边距)ggplot2 [英] Remove white space (i.e., margins) ggplot2 in R
问题描述
我试图在R中使用 GGPLOT2
来绘制一个饼图。我想这样做以省略额外的空白区域。
我正在做的是类似于sharoz在这篇文章中所做的这里除了我想包括一个图例。
以下是我正在做的事:
ggplot(DATA ,aes(x = factor(0),fill = factor(LABELS),weight = VALUES))+
geom_bar(width = 1)+
coord_polar(theta ='y')+
指南(fill = guide_legend(title ='LEGEND'))
假设你正在谈论图形上方和下方的额外空白区域,最简单的解决方案就是调整图形设备的大小。这里是宽高比是关键。如果图形设备的纵横比与图的纵横比相匹配,则会消除很多空白。
我用来保存图的代码是 ggsave
,
ggplot(DATA,aes(x = factor(0),fill = factor(LABELS),weight = VALUES))+
geom_bar(width = 1 )+
coord_polar(theta ='y')+
guides(fill = guide_legend(title ='LEGEND'))
ggsave(plot.png,width = 10,height = 5)
只要玩弄宽度
和身高
在 ggsave
中,直到您满意为止。
I'm trying to plot a pie chart using GGPLOT2
in R. I want to do this in such a way as to omit the extra margin space.
What I'm doing is similar to what sharoz did in this post here except I want to include a legend.
Here is what I'm doing:
ggplot(DATA, aes(x=factor(0),fill=factor(LABELS),weight=VALUES)) +
geom_bar(width=1) +
coord_polar(theta='y') +
guides(fill=guide_legend(title='LEGEND'))
Assuming you are talking about the extra white space above and below the figure, the easiest solution is just to tweak the size of the graphics device. Here is aspect ratio is the key. If the aspect ratio of the graphics device matches that of the plot, you get rid of a lot of the whitespace.
What I use to save the plot is ggsave
, in code:
ggplot(DATA, aes(x=factor(0),fill=factor(LABELS),weight=VALUES)) +
geom_bar(width=1) +
coord_polar(theta='y') +
guides(fill=guide_legend(title='LEGEND'))
ggsave("plot.png", width = 10, height = 5)
Just play around with width
and height
in ggsave
until you are happy with the result.
这篇关于删除R中的空白(即边距)ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!