在 R 函数 ggplotly(来自 plotly 包)中,如何调整标签内容
In R function ggplotly ( from plotly package), how to adjust the label content
当我使用 ggplotly 函数(来自 plotly 包)时,如何更改 pop 标签内容(删除附图中红色矩形中的标签内容)?
library(tidyverse)
library(plotly)
mdate <- c(44197,44198,44199,44200,44201,44202,44203,44204,44205,44206,44207,44208,44209,44210,44211,44212,44213,44214,44215,44216,44217,44218,44219,44220,44197,44198,44199,44200,44201,44202,44203,44204,44205,44206,44207,44208,44209,44210,44211,44212,44213,44214,44215,44216,44217,44218,44219,44220)
myear <- c(2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020)
amount <- c(45,2,2,87,93,32,31,42,84,93,24,13,12,48,39,33,88,78,15,6,51,55,32,93,14,16,11,84,47,87,40,45,57,76,24,91,11,96,44,82,99,17,75,59,22,89,61,93)
p <- data.frame(mdate,myear,amount) %>%
mutate(mdata=as.Date(mdate),
myear=as.factor(myear)) %>%
ggplot(aes(x=as.Date(mdate),y=amount,color=myear))+geom_line()+
theme_minimal()
ggplotly(p)
我们可以将工具提示的规范(即要使用的值)传递给 plotly:
p <- data.frame(mdate,myear,amount) %>%
mutate(mdata=as.Date(mdate, origin ="1904-01-01"),
myear=as.factor(myear)) %>%
ggplot(aes(x=mdata, y=amount, color=myear)) +
geom_line()+
theme_minimal()
ggplotly(p, tooltip = c("y", "colour"))
P.S。虽然 ggplot2 确实允许拼写“颜色”和“颜色”,但情节似乎坚持使用“颜色”...
当我使用 ggplotly 函数(来自 plotly 包)时,如何更改 pop 标签内容(删除附图中红色矩形中的标签内容)?
library(tidyverse)
library(plotly)
mdate <- c(44197,44198,44199,44200,44201,44202,44203,44204,44205,44206,44207,44208,44209,44210,44211,44212,44213,44214,44215,44216,44217,44218,44219,44220,44197,44198,44199,44200,44201,44202,44203,44204,44205,44206,44207,44208,44209,44210,44211,44212,44213,44214,44215,44216,44217,44218,44219,44220)
myear <- c(2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020,2020)
amount <- c(45,2,2,87,93,32,31,42,84,93,24,13,12,48,39,33,88,78,15,6,51,55,32,93,14,16,11,84,47,87,40,45,57,76,24,91,11,96,44,82,99,17,75,59,22,89,61,93)
p <- data.frame(mdate,myear,amount) %>%
mutate(mdata=as.Date(mdate),
myear=as.factor(myear)) %>%
ggplot(aes(x=as.Date(mdate),y=amount,color=myear))+geom_line()+
theme_minimal()
ggplotly(p)
我们可以将工具提示的规范(即要使用的值)传递给 plotly:
p <- data.frame(mdate,myear,amount) %>%
mutate(mdata=as.Date(mdate, origin ="1904-01-01"),
myear=as.factor(myear)) %>%
ggplot(aes(x=mdata, y=amount, color=myear)) +
geom_line()+
theme_minimal()
ggplotly(p, tooltip = c("y", "colour"))
P.S。虽然 ggplot2 确实允许拼写“颜色”和“颜色”,但情节似乎坚持使用“颜色”...