2017-06-29 88 views
2

我想創建一個簡單的陰謀,但非標準的休息。yaxis陰謀的非標準破壞

這對我的數據的代碼:

> 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,如附圖所示。我可以在其他軟件中更改它,所以不要把重點放在其他軟件上。

回答

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