R中的馅饼甜甜圈图
Pie-Donut Chart in R
我想创建一个如下图所示的圆饼图:
为此,我正在使用下一个代码:
PieDonut(df1, aes(Species, Costs, count=Entries),
ratioByGroup = F, explode = 1, r0 = 0.5, r1 = 0.7)
但我没有得到两个不同的(独立的)图表。这是结果:
如您所见,两组的比率并不相同:
第一个甜甜圈应该根据变量“Costs”和第二个“Entries”
这是我正在使用的数据:
structure(list(Species = c("Cercopagis pengoi", "Dreissena polymorpha"
), Costs = c(0.27, 33.27), Entries = c(7L, 5L), fraction = c(0.00805008944543828,
0.991949910554562), ymax = c(0.00805008944543828, 1), ymin = c(0,
0.00805008944543828)), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
非常感谢您的帮助,
提前致谢。
这里我得到了一个plotly
选项。您可以使用两个 add_pie
创建两个饼图,一个用于孔,一个用于外圆。您可以使用以下代码:
library(plotly)
library(dplyr)
plot_ly(df1) %>%
add_pie(labels = ~`Species`, values = ~`Costs`,
type = 'pie', hole = 0.7, sort = F,
marker = list(line = list(width = 2))) %>%
add_pie(df1, labels = ~`Species`, values = ~`Entries`,
domain = list(
x = c(0.15, 0.85),
y = c(0.15, 0.85)),
sort = F) %>%
layout(title = "Chart",
legend = list(title = list(text = "Species")))
输出:
数据
df1 <- structure(list(Species = c("Cercopagis pengoi", "Dreissena polymorpha" ), Costs = c(0.27, 33.27), Entries = c(7L, 5L), fraction = c(0.00805008944543828, 0.991949910554562), ymax = c(0.00805008944543828, 1), ymin = c(0, 0.00805008944543828)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))
我想创建一个如下图所示的圆饼图:
为此,我正在使用下一个代码:
PieDonut(df1, aes(Species, Costs, count=Entries),
ratioByGroup = F, explode = 1, r0 = 0.5, r1 = 0.7)
但我没有得到两个不同的(独立的)图表。这是结果:
如您所见,两组的比率并不相同: 第一个甜甜圈应该根据变量“Costs”和第二个“Entries”
这是我正在使用的数据:
structure(list(Species = c("Cercopagis pengoi", "Dreissena polymorpha"
), Costs = c(0.27, 33.27), Entries = c(7L, 5L), fraction = c(0.00805008944543828,
0.991949910554562), ymax = c(0.00805008944543828, 1), ymin = c(0,
0.00805008944543828)), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
非常感谢您的帮助, 提前致谢。
这里我得到了一个plotly
选项。您可以使用两个 add_pie
创建两个饼图,一个用于孔,一个用于外圆。您可以使用以下代码:
library(plotly)
library(dplyr)
plot_ly(df1) %>%
add_pie(labels = ~`Species`, values = ~`Costs`,
type = 'pie', hole = 0.7, sort = F,
marker = list(line = list(width = 2))) %>%
add_pie(df1, labels = ~`Species`, values = ~`Entries`,
domain = list(
x = c(0.15, 0.85),
y = c(0.15, 0.85)),
sort = F) %>%
layout(title = "Chart",
legend = list(title = list(text = "Species")))
输出:
数据
df1 <- structure(list(Species = c("Cercopagis pengoi", "Dreissena polymorpha" ), Costs = c(0.27, 33.27), Entries = c(7L, 5L), fraction = c(0.00805008944543828, 0.991949910554562), ymax = c(0.00805008944543828, 1), ymin = c(0, 0.00805008944543828)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))