當我使用函式 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)

uj5u.com熱心網友回復:
我們可以將工具提示的規范(即使用哪些值)傳遞給繪圖:
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"))

PS雖然ggplot2確實允許拼寫“顏色”和“顏色”,但情節似乎堅持“顏色”......
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318544.html
上一篇:如果列包含R資料框中的特定文本,則洗掉重復的觀察結果
下一篇:R函式將行中的日期轉換為時間跨度
