修改刻度的对数轴
Logarithmic axis with modified ticks
我正在尝试重新创建下图,但无法消除 x > 3 的 'half-step' 增量。有更好的方法吗?我现在正在使用 ggplot2
- 正确使用然后计划切换到 plotly
进行交互式绘图。
代码
只显示 3 个 PoC 跟踪:
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)))))
通过设置 panel.grid.minor = element_blank()
.
可以通过主题删除次要网格线
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)) +
theme(panel.grid.minor = element_blank())
由 reprex package (v0.3.0)
于 2020-05-28 创建
我正在尝试重新创建下图,但无法消除 x > 3 的 'half-step' 增量。有更好的方法吗?我现在正在使用 ggplot2
- 正确使用然后计划切换到 plotly
进行交互式绘图。
代码
只显示 3 个 PoC 跟踪:
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)))))
通过设置 panel.grid.minor = element_blank()
.
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)) +
theme(panel.grid.minor = element_blank())
由 reprex package (v0.3.0)
于 2020-05-28 创建