簡體   English   中英

R 中包含多行文本的餅圖圖例

[英]Pie chart legend with multiple lines of text in R

我正在嘗試使用以下代碼將我的長行文本拆分為餅圖圖例中的多行。 當前代碼創建了一個帶有大量空白的圖例,並且文本覆蓋了方框。 該框也在餅圖上方。 我究竟做錯了什么?

v4_class_combined_slices <- c(27, 121, 27)
v4_class_combined_labels <- c("Bacteroidia", "Clostridia", "Actinobacteria/Coriobacteriia/\n4C0d.2/Bacilli/Erysipelotrichi/\nBetaproteobacteria/Gammaproteobacteria/\nMollicutes/RF3")
piepercent <- round(100*v4_class_combined_slices/sum(v4_class_combined_slices), 1)
piepercent2 <- paste(piepercent, sep = " ", "%")
pie(v4_class_combined_slices, labels = piepercent2, col = rainbow(3))
legend("topright", v4_class_combined_labels, cex = 0.9, text.width = 1.5, yjust = 0, fill = rainbow(length(v4_class_combined_labels)))

您只需要調整 cex 和 text.width。

圖例(“topright”,v4_class_combined_labels,cex = 0.4,text.width = 1.0,yjust = 0.0,fill = rainbow(長度(v4_class_combined_labels)))

密碼為Plot

它會起作用。我用過 ggplot2,ggrepel 庫。 確保安裝 [1]: https://i.stack.imgur.com/Q4ZcB.png

暫無
暫無

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

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