2017-04-16 1 views
1

私のグラフは次のようになります。私が使用したコードは、私が唯一コブルの間に線をプロットし、そして自由を削除するこのx値がタイプ係数の場合、複数折れ線グラフ(ggplot)の作図領域の限界をどのように設定するのですか?

graph_substrat <- ggplot(substrat_long, aes(x=substrat,y=value, 
+ group=variable, linetype=variable)) + geom_line() + ylab("Suitability Index") 
+ xlab("Substrat") + background_grid(major = "xy", minor = "none") 

graph_substrat <- graph_substrat + theme(legend.position="none") 

ある

graph

スペースは、グラフの始めと終わりにあるので、ラインはY軸から始まります(または少なくともそれに最も近く、X軸の最後のティックで終わります)。

私はlimitsexpandcoord_cartesianで試してみましたが、うまくいきませんでした。

Xはfactorであり、numericではないことに注意してください。

答えて

1

expand = c(0,0)scale_x_discreteに記載すると、hereとなります。 expand = c(0,0)

library(ggplot2) 
ggplot(iris, aes(x = Species, y = Petal.Length)) + 
    stat_summary(fun.y = "mean", geom = "bar") 

enter image description here

一つに:

はこのプロットを比較

ggplot(iris, aes(x = Species, y = Petal.Length)) + 
    stat_summary(fun.y = "mean", geom = "bar") + 
    scale_x_discrete(expand = c(0,0)) 

enter image description here

+0

感謝を!私は 'expand = c(0,0)'で解決しようとしましたが、私は間違った美学のためにそれを行いました。 'scale_x_discrete(expand = c(0,0))'はトリックを行います! –

関連する問題