我正在使用R和Plotly。我面临着一个与使用这个库制作小平面图有关的问题。下面你可以看到我的数据示例以及我尝试在Plotly中使用两个甜甜圈图制作小平面图的尝试。
library(plotly)
library(dplyr)
# Get Manufacturer
mtcars$manuf <- sapply(strsplit(rownames(mtcars), " "), "[[", 1)
df <- mtcars
df <- df %>% group_by(manuf)
df <- df %>% summarize(count = n())
# Donut 1
fig <- df %>%
plot_ly(labels = ~manuf, values = ~count) %>%
add_pie(hole = 0.6) %>%
layout(
title = "Donut charts using Plotly 1",
showlegend = TRUE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
annotations = list(
x = 0, y = -0.1,
showarrow = FALSE,
xref = 'paper',
yref = 'paper',
align = 'left'
))
# Donut 2
fig1 <- df %>%
plot_ly(labels = ~manuf, values = ~count) %>%
add_pie(hole = 0.6) %>%
layout(
title = "Donut charts using Plotly 2",
showlegend = TRUE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
annotations = list(
x = 0, y = -0.1,
showarrow = FALSE,
xref = 'paper',
yref = 'paper',
align = 'left'
))
# Making Facet
facet_fig <- subplot(
fig,
fig1,
nrows = 1,
margin = 0.05
)
facet_fig
字符串
这段代码产生两个圆环图,但问题是,这些图可以在同一个地方用命令subplot,如下面的图片所示。
的数据
谁能帮我解决这个问题,把两个甜甜圈图在同一个图(面图)?
1条答案
按热度按时间kxxlusnw1#
我认为问题在于你如何绘制数据以及绘制什么数据:下面是一个
am
和manuf
计数的例子:字符串
的数据