删除空白(即。,利润率)ggplot2在R。

时间:2021-05-12 06:09:18

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')) 

删除空白(即。,利润率)ggplot2在R。

1 个解决方案

#1


2  

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中使用宽度和高度,直到您对结果满意为止。

#1


2  

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中使用宽度和高度,直到您对结果满意为止。