相关疑难解决方法(0)

分层/多级饼图

有没有办法在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, …
Run Code Online (Sandbox Code Playgroud)

plot r ggplot2 pie-chart

14
推荐指数
2
解决办法
5735
查看次数

如何为绘图森伯斯特图格式化数据

我正在尝试通过 R 使用 Plotly 制作森伯斯特图。我正在努力处理层次结构所需的数据模型,无论是在概念化它是如何工作的方面,还是看看是否有任何简单的方法来转换常规数据框,用代表不同层次级别的列,转换为所需的格式。

我已经查看了 R 中绘图森伯斯特图表的示例,例如,here,并查看了参考页面,但没有完全获得数据格式的模型。

# Create some fake data - say ownership and land use data with acreage
df <- data.frame(ownership=c(rep("private", 3), rep("public",3),rep("mixed", 3)), 
                 landuse=c(rep(c("residential", "recreation", "commercial"),3)),
                 acres=c(108,143,102, 300,320,500, 37,58,90))

# Just try some quick pie charts of acreage by landuse and ownership
plot_ly(data=df, labels= ~landuse, values= ~acres, type='pie')
plot_ly(data=df, labels= ~ownership, values= ~acres, type='pie')

# This doesn't render anything... not that I'd expect it to given the data format doesn't seem …
Run Code Online (Sandbox Code Playgroud)

r plotly sunburst-diagram r-plotly

7
推荐指数
1
解决办法
3204
查看次数

使用 ggplot2 的多个依赖级别旭日图/圆环图

我正在尝试创建一个两级旭日/圆环图(用于打印),其中第二级是第一级的详细视图。我已阅读并理解本教程,但我是 R 和 ggplot2 新手,在生成第二个级别时遇到困难。在前面提到的文章中,根级别只有一个元素(有点多余),而我的根有很多元素;其中,二级至少有1个,最多10个要素。

假设我的数据有三列:nametypevalue; 其中nametype分别定义根元素和第二层元素。每个都name恰好有一个type,它是跨 s 的 sall的总和(其中,至少有一个,并且跨s 的集合可能相交或互斥)。例如:valuetypenametype

name  type    value
----- ------- ------
foo   all     444
foo   type1   123
foo   type2   321
bar   all     111
bar   type3   111
baz   all     999
baz   type1   456
baz   type3   543
Run Code Online (Sandbox Code Playgroud)

我可以使用以下方法创建根级别堆栈(在转换为极坐标之前):

data.all <- data[data$type == "all",]
ggplot(data.all, aes(x=1, y=data.all$value, fill=data.all$name)) + geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)

我对第二级堆栈的需要是使type值在值内对齐name,与它们的值成比例: …

r ggplot2 pie-chart donut-chart sunburst-diagram

5
推荐指数
1
解决办法
6537
查看次数

标签 统计

r ×3

ggplot2 ×2

pie-chart ×2

sunburst-diagram ×2

donut-chart ×1

plot ×1

plotly ×1

r-plotly ×1