作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在 R 中创建这样的图表?
以下是图表中显示的数据的摘录:
df <- structure(list(Animal = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Buffalo",
"Goat", "Sheep"), class = "factor"), Texture = structure(c(4L,
4L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 1L, 1L, 4L, 3L, 4L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L), .Label = c("Hard", "Semi-Hard", "Semi-Soft",
"Soft"), class = "factor"), Name = structure(c(16L, 9L, 3L, 21L,
5L, 4L, 10L, 2L, 12L, 11L, 8L, 14L, 1L, 7L, 22L, 15L, 6L, 20L,
18L, 17L, 19L, 13L), .Label = c("Buffalo Blue", "Charolais",
"Chevre Bucheron", "Clochette", "Crottin de Chavignol", "Feta",
"Fleur du Maquis", "Garrotxa", "Golden Cross", "Humboldt Fog",
"Idaho Goatster", "Majorero", "Manchego", "Mozzarella di Bufala Campana",
"Ossau-Iraty", "Pantysgawn", "Pecorino Romano", "Pecorino Sardo",
"Roncal", "Roquefort", "Sainte-Maure de Touraine", "Yorkshire Blue"
), class = "factor")), .Names = c("Animal", "Texture", "Name"
), class = "data.frame", row.names = c(NA, -22L))
最佳答案
那个图太棒了
好吧,在我开始有点疯狂之前,我已经走了这么远。简而言之,有一种快速的非 ggplot2 方式(它几乎可以给你你想要的东西)和一个长的 ggplot2 方式(它几乎可以给你你想要的东西)。快速方法(使用 df
作为上面的示例数据给出):
devtools::install_github("timelyportfolio/sunburstR")
library(sunburstR)
df1 <- df %>%
group_by(Animal) %>%
unite(col=Type, Animal:Name, sep = "-", remove=T)
df1$Type <- gsub(" ", "", df1$Type)
df1$Index <- 1
sunburst(df1)
df1 <- df %>%
mutate(Colour = ifelse(.$Animal == "Goat", "#CD9B1D", ifelse(.$Animal == "Sheep", "#EEC900", "#FFD700"))) %>%
mutate(Index = 1) %>%
group_by(Animal)
First <- ggplot(df1) + geom_bar(aes(x=1, y=Animal, fill=Animal,
label = Animal), position='stack', stat='identity', size=0.15)
+ theme(panel.grid = element_blank(), axis.title=element_blank(),
legend.position="none", axis.ticks=element_blank(),
axis.text = element_blank())
Second <- First
+ geom_bar(data=df1, aes(x=2, y=Animal, fill=Texture, group=Animal),
position='stack', stat='identity', size=0.15, colour = "black")
+ scale_color_brewer(palette = "YlOrBr")
+ scale_fill_brewer(palette = "YlOrBr")
+ theme(axis.title=element_blank(), legend.position="none",
axis.ticks=element_blank(), axis.text = element_blank())
Third <- Second + geom_bar(data=df1, aes(x=3, y=Animal, fill=Name),
position='stack', stat='identity', size=0.15, colour = "black")
+ scale_fill_manual(values = c("#EEC900", "#FFD700", "#CD9B1D",
"#FFD700", "#DAA520", "#EEB422", "#FFC125", "#8B6914", "#EEC591",
"#FFF8DC", "#EEDFCC", "#FFFAF0", "#EEC900", "#FFD700", "#CDAD00",
"#FFF68F", "#FFEC8B", "#FAFAD2", "#FFFFE0", "#CD853F", "#EED8AE",
"#F5DEB3", "#FFFFFF", "#FFFACD", "#D9D9D9", "#EE7600", "#FF7F00",
"#FFB90F", "#FFFFFF"))
+ theme(axis.title=element_blank(), legend.position="none",
axis.ticks=element_blank(), axis.text.y = element_blank(),
panel.background = element_rect(fill = "black"))
Third + coord_polar('y')
关于r - 分层/多级饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17069436/
有人可以帮我理解为什么我的饼图百分比计算不正确吗?看截图: 根据我的计算,如 RHS 上所示,支出百分比应为 24.73%。传递给 Highcharts 的值如下:- 花费:204827099.36-
我正在制作圆环饼图。 我设置数据的颜色并获取钻取(它是保存外部切片的数据和配置的对象)切片的颜色为同一组颜色。我想设置要在向下钻取对象中使用的不同颜色数组。请参阅附图(外层切片有两种颜色:橙色和透明)
我是一名优秀的程序员,十分优秀!