简体   繁体   English

删除R中的空格(即边距)ggplot2

[英]Remove white space (i.e., margins) ggplot2 in R

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. 我正在尝试使用R中的GGPLOT2绘制饼图。我想这样做以省略额外的边距空间。

What I'm doing is similar to what sharoz did in this post here except I want to include a legend. 我在做什么是类似于sharoz没有在这个岗位这里除了我想包括一个传奇。

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: 我用来保存图的是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)

Just play around with width and height in ggsave until you are happy with the result. 只需在ggsave使用widthheight ,直到您对结果感到满意为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM