工具提示删除回归线ggplotly
Tooltip removes regression line ggplotly
我在server.R中有以下代码:
library(shiny)
library(plotly)
art.data <- read.csv("data1.csv", stringsAsFactors = FALSE)
shinyServer(function(input, output) {
output$distPlot <- renderPlotly({
col.str <- paste0(input$colspa, ".", input$rgbchoice, ".median")
p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]], text = paste0(artist, "<br>", art))) + geom_point(size = 1) + xlab("Year") + stat_smooth(method = loess, se = FALSE)
ggplotly(p , tooltip = "text")
})
})
如果我删除工具提示,则回归线会出现在输出图中,但包含工具提示后,回归线不会出现在图中。有什么解决方案可以将两者结合在一起吗?
With tooltip
Without tooltip in ggplotly() and text in aes()
审美text
需要审美group
.
让我们开始考虑这个例子:
art.data <- data.frame(year=1430:1490, y=rnorm(61),
artist=sample(LETTERS,61, replace=T), art=sample(letters,61, replace=T))
col.str <- 2
library(ggplot2)
ggplot(art.data, aes(x = year, y = art.data[[col.str]],
text=paste0(artist, "<br>", art))) +
geom_point(size = 1) +
stat_smooth(method = loess, se = FALSE) +
xlab("Year")
在这种情况下,黄土线未绘制在图表上:
在ggplot
美学中添加group=1
解决问题:
p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]],
text=paste0(artist, "<br>", art), group=1)) +
geom_point(size = 1) +
stat_smooth(method = loess, se = FALSE) +
xlab("Year")
p
和 ggplotly
现在运行良好:
library(plotly)
ggplotly(p, tooltip="text")
我在server.R中有以下代码:
library(shiny)
library(plotly)
art.data <- read.csv("data1.csv", stringsAsFactors = FALSE)
shinyServer(function(input, output) {
output$distPlot <- renderPlotly({
col.str <- paste0(input$colspa, ".", input$rgbchoice, ".median")
p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]], text = paste0(artist, "<br>", art))) + geom_point(size = 1) + xlab("Year") + stat_smooth(method = loess, se = FALSE)
ggplotly(p , tooltip = "text")
})
})
如果我删除工具提示,则回归线会出现在输出图中,但包含工具提示后,回归线不会出现在图中。有什么解决方案可以将两者结合在一起吗?
With tooltip
Without tooltip in ggplotly() and text in aes()
审美text
需要审美group
.
让我们开始考虑这个例子:
art.data <- data.frame(year=1430:1490, y=rnorm(61),
artist=sample(LETTERS,61, replace=T), art=sample(letters,61, replace=T))
col.str <- 2
library(ggplot2)
ggplot(art.data, aes(x = year, y = art.data[[col.str]],
text=paste0(artist, "<br>", art))) +
geom_point(size = 1) +
stat_smooth(method = loess, se = FALSE) +
xlab("Year")
在这种情况下,黄土线未绘制在图表上:
在ggplot
美学中添加group=1
解决问题:
p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]],
text=paste0(artist, "<br>", art), group=1)) +
geom_point(size = 1) +
stat_smooth(method = loess, se = FALSE) +
xlab("Year")
p
和 ggplotly
现在运行良好:
library(plotly)
ggplotly(p, tooltip="text")