gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:42:44 26 4
gpt4 key购买 nike

我有一些数据,我想用它做一个饼图。在数据中,有一个类别太低,它在图表上的标签看起来不太好。我的代码和各自的情节如下。

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

大家可以看到,黄色的category不好看,一般来说,我想把这些labels的样式改一下,比如这样:

enter image description here

当然,我想保留传说,有什么想法吗?。提前致谢

最佳答案

使用 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

关于r - 如何提高饼图的可视化质量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58184353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com