2012-08-30 29 views
7

私はこのような何かを行うことによってggplot2で異なる色で各シリーズをプロットすることができます...ggplot - 変更線幅

colours <- c('red', 'blue') 
p <- ggplot(data=m, mapping=aes_string(x='Date', y='value')) 
p <- p + geom_line(mapping=aes_string(group='variable', colour='variable'), size=0.8) 
p <- p + scale_colour_manual(values=colours) 

は、私は各シリーズごとに異なる線幅を設定するために行うことができ、同等なものはありますか? (つまり、私がトレンドと季節調整シリーズをプロットする薄い青色の線をプロットするために太い赤の線を使用する。)

+2

をあなたは '( 'M')あなたのデータをdput'することはできますか? – seancarmody

答えて

11

は、私はちょうどあなたのデータフレームに新しい数値変数を追加します

##You will need to change this to something more appropriate 
##Something like: 
##m$size = as.numeric(m$variable == "seasonal") 
m$size = rep(c(0, 1), each=10) 
私が表示されているサイズの伝説を避けるために guide=FALSEを追加しました

p = p + geom_line(aes(group=variable, colour=variable, size=size)) 
##Set the size scale 
p + scale_size(range=c(0.1, 2), guide=FALSE) 

お知らせ:

は、あなたのplotコマンドに美的サイズを追加します。

+0

どうすればいいですか?私は、伝説のラインを太くしたいが、プロットのラインを薄くしたい。 – baltazar

+0

あなたはおそらく新しい質問をするのに最適でしょう。 – csgillespie

+0

http://stackoverflow.com/q/16356052/258421 – baltazar

5

あなたはそれが好き行うことができます:

x <- 1:10 
y1 <- x 
y2 <- 1.5*x 
df <- data.frame(x=rep(x, 2), y=c(y1, y2), id=as.factor(rep(1:2, each=10))) 
ggplot(df) + geom_line(aes(x=x,y=y,group=id, colour=id, size=id)) + 
scale_size_manual(values=c(1,4)) 
+0

'scale_size_manual'は本当に便利な機能です –

関連する問題