我正在尝试重新创建下图,但无法摆脱x的“半步长”增量。3.有更好的方法吗?我现在使用ggplot2
-正确设置,然后计划切换到plotly
进行交互式绘图。
代码
仅显示PoC的3条痕迹:
set.seed(69)
library(data.table)
library(ggplot2)
k <- lapply(1:10, function(z){
ret <- sample(x = (5*z):100,
size = 20,
replace = T)
dat <- data.table(V1 = ret[order(ret)] )
colnames(dat) <- paste('trace', z, sep = '')
return(dat)
})
dat <- do.call(cbind, k)
dat$size <- c(seq(0.1, 1, 0.1), 2:11)
ggplot(dat[size >= 0.2, ], aes(x = size)) +
geom_line(size = 1.5, aes(y = trace1), color = '#003366') +
geom_line(size = 1.5, aes(y = trace2),
color = rgb(red = 0, green = 103, blue = 62, maxColorValue = 255)) +
geom_line(size = 1.5, aes(y = trace3), color = '#b20000') +
scale_x_log10(breaks = c(seq(0.1, 1, 0.1), 2:11))
输出
所需图
无需以ggplot2
开头。您可以直接在plotly
:
library(dplyr)
library(tidyr)
library(plotly)
dat %>%
filter(size >= 0.2) %>%
pivot_longer(-size) %>%
plot_ly(x = ~size, y = ~value, color = ~name, type = 'scatter', mode = 'lines') %>%
layout(xaxis = list(type = "log",
tickvals = as.list(c(seq(0.2,1,0.2), seq(2,10,2)))))