2017-03-01 10 views
8

これは、基線を使用しています。x軸とy軸の範囲を制御できます。ここで、正確に線を描画します。私はまさに基本プロットのような軸線を追加するにはどうすればよいこれをggplotにプロットします。範囲内のy軸線の制御

plot(mtcars$mpg, mtcars$hp, ylim = c(0, 400), xlim = c(0, 50), axes = F, xlab = 'mpg', ylab = 'hp', pch = 16) 
axis(side = 2, at = seq(100, 400, 100)) 
axis(side = 1, at = seq(10, 30, 10)) 

enter image description here

ggplot(data = mtcars, aes(x = mpg, y = hp))+geom_point()+ 
theme(panel.background = element_blank())+ 
scale_x_continuous(breaks = seq(10, 30, 10), limits = c(0, 50))+ 
scale_y_continuous(breaks = seq(100, 400, 100), limits = c(0, 400)) 

enter image description here

?私はscale_y_continuousscale_x_continuousを試しましたが、常にプロットの終わりまで描画します。

答えて

6

あなたはggthemesパッケージを使用してそこに着くことができます:あなたがしたい場合

ggplot(data = mtcars, aes(x = mpg, y = hp))+geom_point()+ 
    geom_rangeframe(data = data.frame(mpg = c(10, 30), hp = c(100, 400))) + 
    theme_tufte() + 
    scale_x_continuous(breaks = seq(10, 30, 10), limits = c(0, 50))+ 
    scale_y_continuous(breaks = seq(100, 400, 100), limits = c(0, 400)) 

enter image description here

あなたはまた、それらを手動で描くことができます:

ggplot(data = mtcars, aes(x = mpg, y = hp))+geom_point()+ 
    geom_segment(aes_all(c('x', 'y', 'xend', 'yend')), 
       data = data.frame(x = c(0, 10), xend = c(0, 30), y = c(100, 0), yend = c(400, 0))) + 
    theme(panel.background = element_blank()) + 
    scale_x_continuous(breaks = seq(10, 30, 10), limits = c(0, 50), expand = c(0, 0))+ 
    scale_y_continuous(breaks = seq(100, 400, 100), limits = c(0, 400), expand = c(0, 0)) 

enter image description here

+0

を感謝、 私これまでに(theme_hc()を使って)試してみました。しかし、私はggthemesを使ってこれをしたい。出来ますか ? – PoisonAlien

+0

スケールを拡大するときにセグメントを手動で描画できると思います。 – Axeman

+0

ええ、私が気にしていたことです。私はそれを試みます。この成熟したggplotにはこのオプションがないというのは驚くべきことです。 – PoisonAlien

関連する問題