【发布时间】:2021-09-01 16:11:19
【问题描述】:
我正在尝试在我的闪亮应用程序中构建一个甜甜圈图,该应用程序使用情节,类似于另一个问题的this one)。但是'我的情节从未出现。我研究了其他答案(例如 this one、this one 和 this one),但它们并没有让我更接近我的答案。
我做错了什么?
library(shiny)
library(dplyr)
library(plotly)
my_colors <- c("#00A3AD", "#FF8200", "#753BBD")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
fluidRow(
plotlyOutput("count_by_person")
))
))
server <- function(input, output) {
output$count_by_person <- renderPlotly({
data <- tibble(name = c("Justin", "Corey", "Sibley"),
n = c(1, 3, 6),
prop = c(.1, .3, .6))
plot_ly(data, aes(x = 2, y = prop, fill = name)) +
geom_bar(stat = "identity", color = "white") +
coord_polar(theta = "y", start = 0)+
geom_text(aes(y = lab.ypos, label = paste0("n = ", n, ", \n", prop, "%")), color = "white")+
scale_fill_manual(values = my_colors) +
theme_void() +
xlim(.5, 2.5)
})
}
shinyApp(ui, server)
【问题讨论】:
-
尝试使用
ggplot(...)而不是plot_ly,然后使用plotly::ggplotly将您的绘图转换为绘图对象。不幸的是,我担心 ggplotly 无法将您的 ggplot donut 转换为 plotly donut。
标签: r plot shiny plotly r-plotly