y轴的非标准断裂

时间:2017-06-29 10:01:09

标签: r

我想创建一个简单的情节但是有非标准的休息。

这是我的数据代码:

> dput(dt1)
c(15.9540654816514, 37.5416557213931, 143.317585514018, 317.329051086954, 
736.342269565211, 611.759999999995, 1145.49376842104, 3287.57274999997
)
> dput(dt2)
c(7.74957214839424, 17.5499521829522, 47.8167516932271, 72.1468924428822, 
131.457629238329, 119.135097468354, 193.812365333332, 339.109355072461
)
> dput(dt3)
c(3.43850794565666, 11.4081262121212, 24.6747108504399, 54.7253625128734, 
85.7360432084306, 89.7801271317832, 117.764457806452, 152.859368367347
)

我希望实现类似的目标:

Output

忽略该图表上的红点。

这是我到目前为止编写的代码。但是,改变y休息的方法并不奏效。

plot(dt1,col="blue",cex = 1.8,xlim=c(0,10), ylim = c(1,5000), yaxt = "n", bty="n",xlab="",ylab="")
axis(side = 2, at = C(10,100,1000,5000)
points(dt2,col="green",cex = 1.8)
points(dt3,col="red",cex = 1.8)

有可能吗?我想在附图中创建相同的xlabel。我也可以在其他软件中更改它,所以不要主要关注它。

1 个答案:

答案 0 :(得分:4)

这是我能想到的最接近ggplot2

library(data.table)
library(dplyr)
library(ggplot2)
theme_set(theme_bw())
dat <- rbindlist(list(
  data.table(dt = "dt1",
             y = c(15.9540654816514, 37.5416557213931, 143.317585514018, 317.329051086954, 
             736.342269565211, 611.759999999995, 1145.49376842104, 3287.57274999997)), 
  data.table(dt = "dt2",
             y = c(7.74957214839424, 17.5499521829522, 47.8167516932271, 72.1468924428822, 
                   131.457629238329, 119.135097468354, 193.812365333332, 339.109355072461)),
  data.table(dt = "dt3",
             y  = c(3.43850794565666, 11.4081262121212, 24.6747108504399, 54.7253625128734, 
                    85.7360432084306, 89.7801271317832, 117.764457806452, 152.859368367347))))

## generate lables
labs <- paste(rep(1:4, c(2,3,2,1)), rep(c(1,2,3,4,3,4), c(1,2,1,1,1,2)), sep = '\n-\n') 
## create x variable
dat[, x := rep(1:8, 3) %>% factor(labels = labs)]
## plot 
ggplot(dat, aes(x = x, y = y, colour = dt)) + 
  geom_point() + 
  scale_y_log10(limits = c(1, 10000), 
                breaks = 10^(0:4)) +
  xlab("") + ylab("") 
ggsave('temp.png', width = 4, height = 3)

输出如下: enter image description here