如何提高饼图的可视化质量?

3

我有一些数据,想从中制作饼图。在数据中,有一个类别太少了,在图表上的标签看起来不太好。以下是我的代码和相应的图表。

library("readr")
library("fmsb")
library("car")
library("normtest")
library("nortest")
library("moments")
library("readxl")   
library("ggplot2")
library("stats")
library("data.table")
library("dplyr")
library("plotly")

count.data <- data.frame(
  Tópico = c("Problemas de ruteo", "Diseño de redes ", "Ruteo y localización", "Modelos de inventario","Problemas de localización","Problemas de asignación","Medición de riesgo"),
  n = c(27,6,16,10,31,6,4),
  prop = c(27,6,16,10,31,6,4)
)
count.data

count.data <- count.data %>%
  arrange(desc(Tópico)) %>%
  mutate(lab.ypos = cumsum(prop) - 0.5*prop)
count.data

mycols <- c("#A1E89D", "#EFC000FF", "#868686FF", "#CD534CFF","#7AD55D","#9333FF","#FF33CE")

ggplot(count.data, aes(x = "", y = prop, fill =Tópico)) +
  geom_bar(width = 1.8, stat = "identity", color = "black") +
  coord_polar("y", start = 0)+
  geom_text(aes(y = lab.ypos, label = paste0(prop, "%")), color = "black",cex=3.5)+
  scale_fill_manual(values = mycols)+ theme(axis.text.x=element_blank())+theme_void()

情节是:

enter image description here

如您所见,黄色类别看起来不好,通常情况下,我想更改这些标签的样式,例如这样:

enter image description here

当然,我想保留图例,有什么建议吗?先谢谢了。
1个回答

1
一个使用Plotly的简单解决方案。
plot_ly(count.data, labels = ~count.data$n, values = ~count.data$n, type = 'pie',
        textposition = 'outside',
        textinfo = 'label',
        insidetextfont = list(color = '#FFFFFF'),
        hoverinfo = 'text',
        marker = list(line = list(color = '#FFFFFF', width = 1)),showlegend = TRUE)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接