R 有没有办法更改ggplotly中的标签名称
我面临解决以下问题的挑战。请这里的专家在这方面帮助我。在我放置正确的reprex之前,让我在这里解释一下问题:R 有没有办法更改ggplotly中的标签名称,r,ggplot2,R,Ggplot2,我面临解决以下问题的挑战。请这里的专家在这方面帮助我。在我放置正确的reprex之前,让我在这里解释一下问题: df sd x y x1 y1 1 1 12 1019 0.3867382 1.3484106 2 2 20 1016 1.7618076 0.8860984 3 3 7 1006 -0.4726801 -0.6549423 4 4 3 1009 -1.
df
sd x y x1 y1
1 1 12 1019 0.3867382 1.3484106
2 2 20 1016 1.7618076 0.8860984
3 3 7 1006 -0.4726801 -0.6549423
4 4 3 1009 -1.1602147 -0.1926301
我必须画x和y,但它们的比例不同。所以我所做的是对数据进行标准化,得到x1和y1。规范化公式是
((x-均值(x))/sd(x)
现在我需要绘制x1
和y1
。因此,我进行了一些数据争论,下面是它的reprex。我正在获取输出,但这里的主要问题是,由于x1
和y1
正在绘制,当我将光标移到上面时,它会显示x1
和y1
值,这是我不想要的。Even尽管绘制了x1
和y1
,但我需要显示实际值(x
和y
值)。有没有办法实现这一点
library(ggplot2)
library(plotly)
require(reshape)
df <- structure(list(sd = c(1, 2, 3, 4), x = c(12, 20, 7, 3),
y = c(1019, 1016, 1006, 1009),
x1 = c(0.386738249968166, 1.76180758318831, -0.472680083294425, -1.1602147499045),
y1 = c(1.34841060188091, 0.886098395521742, -0.654942292342157, -0.192630085982987)),
row.names = c(NA, -4L), class = "data.frame")
df$x <- NULL
df$y <- NULL
df1 <- melt(df,id=c("sd"))
ggplotly(ggplot(data = df1, aes(x = sd, y = value, color = variable))
+ geom_line(size=0.2))
库(ggplot2)
图书馆(绘本)
需要(重塑)
df可能有很多方法,但是在格式化数据帧之后,您可以使用tooltip=“text”
在此处显示所需的工具提示
df1 <- df
df1$x <- NULL
df1$y <- NULL
dfx <- melt(df1,id=c("sd"))
df2 <- df
df2$x1 <- NULL
df2$y1 <- NULL
dfy <- melt(df2,id=c("sd"))
names(dfy) <- c("sd1", "variable1", "value1")
df <- cbind(dfx,dfy)
ggplotly(ggplot(data = df,aes(x=sd, y=value, color=variable, text=value1))+
geom_line(size=0.2), tooltip = "text")
df1可能有很多方法,但是在格式化数据帧之后,您可以使用tooltip=“text”
在此处显示所需的工具提示
df1 <- df
df1$x <- NULL
df1$y <- NULL
dfx <- melt(df1,id=c("sd"))
df2 <- df
df2$x1 <- NULL
df2$y1 <- NULL
dfy <- melt(df2,id=c("sd"))
names(dfy) <- c("sd1", "variable1", "value1")
df <- cbind(dfx,dfy)
ggplotly(ggplot(data = df,aes(x=sd, y=value, color=variable, text=value1))+
geom_line(size=0.2), tooltip = "text")
df1