簡體   English   中英

減少ggplot2餅圖周圍的邊距

[英]Reduce margins around ggplot2 pie chart

我在文檔中包括一個餅圖,而其他圖表在ggplot2 ,因此我想使用ggplot2來保持圖表的一致性。 但是,餅圖不會擴展到邊距

dat <- structure(list(y = c(0.0714285714285714, 
                            0.0714285714285714, 
                            0.107142857142857, 
                            0.160714285714286, 
                            0.25, 
                            0.339285714285714), 
                      x = structure(c(1L, 3L, 4L, 5L, 6L, 2L), 
                                    .Label = c("1 to 5", "6", "7", "8", "9", "10"), 
                                    class = "factor")), 
                 class = "data.frame", 
                 .Names = c("y", "x"), row.names = c(NA, -6L))

ggplot(dat, aes(x = factor(1), y = y, fill = factor(x))) + 
  geom_bar(width = 1, stat = "identity") + 
  coord_polar(theta  = "y") + 
  theme_grey()

我會使用theme_void() ; 我已經使用theme_grey來說明這一點:餅圖的邊緣在面板中的延伸不夠遠。 如何使餅圖的直徑等於(或非常接近)面板的寬度? 修改width=1scale_x_discrete(expand = c(0,0))無效。 coord_polar的參數似乎也沒有提供任何線索。

在此處輸入圖片說明

這實際上並不能解決您的問題,但確實會將餅圖的區域擴大到大約面板的初始大小。

ggplot(dat, aes(x = factor(1), y = y, fill = factor(x))) + 
geom_bar(width = 1, stat = "identity") + 
coord_polar(theta  = "y") + 
guides(fill=guide_legend(override.aes=list(colour=NA))) +
theme(panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      axis.text.x=element_blank(),
      plot.margin = unit(c(-.75,-.75,-.75,-.75),"cm")
      )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM