[英]Shiny Plotly multiple smoothed lines based on color
提前謝謝你的幫助。 我試圖在一個閃亮的應用程序中使用plotly。 我有點新鮮,所以我道歉,如果這是一個沒腦子。 我想使用一個散點圖,根據輸入$ Col為每個點繪制不同的顏色,然后對於輸入$ Col中的每個組,我想為每種顏色繪制一條平滑的線。 一切正常,除了我使用add_lines()時它只繪制一條線,並且不區分散點圖上的不同顏色。
plot_ly(poolfinderdata1(), type = "scatter", x = ~get(input$X),
y = ~get(input$Y),
mode = "markers",
color = ~get(input$Col),
symbol = as.factor(poolfinderdata1()$Matcher))%>%
add_lines(y = ~fitted(loess(get(input$Y) ~ get(input$X)),
color ~ get(input$Col)))%>%
layout(xaxis =list(title= input$X), yaxis = list(title = input$Y))
ggplot2
已經存在了很長時間,所以它已經有很多你可以使用的東西了,我認為學習它值得付出努力,特別是因為你可以用ggplotly
函數來交互你的情節。 這是解決問題的一種方法:
library(plotly)
library(ggplot2)
data <- poolfinderdata1()
data[[input$Col]] <- as.factor(data[[input$Col]]) # so the color is mapped as discrete
data$Matcher <- as.factor(data$Matcher) # same for the markers
p <- ggplot(data, aes_string(x = input$X, y = input$Y, color = input$Col)) +
geom_point(aes(shape = Matcher)) +
geom_smooth(method = "loess")
ggplotly(p)
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.