当我将光标放在数据点上时,我想使用ggplotly图形来显示实际日期格式而不是数字(默认情况下已转换)。提前谢谢!
这是一个简单的例子:
require(plotly)
require(ggplot2)
x <- c("01/01/2007","04/03/2008","28/11/2008","13/06/2009")
y <- c(25, 50, 75, 100)
x_lab <- "date"
y_lab <- "score"
(mydata <- as.data.frame(cbind(x,y)))
mydata$x <- as.Date(mydata$x, "%d/%m/%Y")
ggplot(mydata, aes(x=x, y=y)) +
geom_point()
ggplotly()
答案 0 :(得分:0)
使用plot_ly()函数代替ggplotly()解决问题!!
以下是具有相同数据的代码:
require(ggplot)
require(plotly)
x <- c("01/01/2007","04/03/2008","28/11/2008","13/06/2009")
y <- c(25, 50, 75, 100)
x_lab <- "date"
y_lab <- "score"
mydata <- as.data.frame(cbind(x,y))
mydata$x <- as.Date(mydata$x, "%d/%m/%Y")
str(mydata)
plot_ly(mydata, x = ~x, y = ~y, type = 'scatter', mode = 'markers',
marker = list(size = 10))
或者,它仍然可以使用ggplotly完成!
require(ggplot)
require(plotly)
x <- c("01/01/2007","04/03/2008","28/11/2008","13/06/2009")
y <- c(25, 50, 75, 100)
x_lab <- "date"
y_lab <- "score"
mydata <- as.data.frame(cbind(x,y))
mydata$x <- as.Date(mydata$x, "%d/%m/%Y")
myplot <- ggplot(mydata, aes(x=x, y=y, label1=x, label2=y)) +
geom_point()
ggplotly(myplot, tooltip = c("label1", "label2"))