所以我在ggplot vs PLotly中遇到散点图问题 . 在我的实际代码中,我使用K-means集群来决定制作每个数据点的颜色 . 但是,我的一些群集只有一个数据点,并且这些群集没有在图上显示(但显示在ggplot2上) . 这是我正在经历的一个简化示例:
shinyUI(
mainPanel(
plotlyOutput('plot2'),
plotOutput('plot4'))
)
只是一个基本的shinyUI页面 . 这是我在服务器上的内容.R方:
output$plot4 <- renderPlot({
qplot(mpg, wt, data=mtcars, colour=ifelse(wt==2.620, 'red', 'blue'),
size=ifelse(wt==2.620, 8, 4))
})
output$plot2 <- renderPlotly({
gg4 <- qplot(mpg, wt, data=mtcars, colour=ifelse(wt==2.620, 'red', 'blue'),
size=ifelse(wt==2.620, 8, 4))
p4 <- ggplotly(gg4)
})
这样就产生了以下image . 在这种情况下,顶部图形是Plotly图像,而底部是ggplot2图像 . 正如您所看到的那样,蓝点仅出现在ggplot2中,但只能在具有该值的mtcars中使用't be found in the Plotly. I chose to single out 2568401 since there' s数据点 .
但是,一旦我切换到以下代码:
output$plot4 <- renderPlot({
print(mtcars[,2])
print(mtcars[,3])
qplot(mpg, wt, data=mtcars, colour=ifelse(mpg==10.4, 'red', 'blue'))
})
output$plot2 <- renderPlotly({
gg4 <- qplot(mpg, wt, data=mtcars, colour=ifelse(mpg==10.4, 'red', 'blue'))
p4 <- ggplotly(gg4)
})
我在这里使用mpg == 10.4,因为mtcars中有两辆车,mpg == 10.4 . 这会产生以下image . 您可以看到它在绘图图和ggplot散点图上都有蓝点 . 我一直无法找到解决方案,所以任何建议都会非常感激!