Remove the empty space (i.e. Fields) of ggplot2 in R

I am trying to build a pie chart using GGPLOT2 in R. I want to do this in such a way as to omit the extra field space.

What I am doing is similar to what charoz did in this post here , except that I want to include a legend.

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

enter image description here

+2
source share
1 answer

Assuming you are talking about an extra space above and below the numbers, the easiest solution is to simply resize the graphics device. Here, aspect ratio is the key. If the aspect ratio of the graphics device matches the aspect ratio of the graph, you get rid of a large number of spaces.

What I use to save the ggsave graph 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 get the result.

+2
source

Source: https://habr.com/ru/post/1242805/


All Articles