0
祝與定製的顏色使用GGPLOT2庫函數每一行線來繪製多模型數據繪圖中的R定製顏色的線條和圖例。我能夠通過ggplot生成隨機顏色這樣做,但如果我試圖把定製顏色,傳說正在消失。請幫我解決這個問題。下面是可重現的例子,我想要一條黑色和一條綠色線與標籤一起。 在此先感謝。使用GGPLOT2
library(ggplot2)
flux<-c(-4.351645e-11 ,7.724330e-10 ,-1.631623e-10,2.832141e-10,-2.396649e-11,
# first model 5 entries
-7.825169e-10 ,-2.534337e-10,-3.837198e-10 ,-2.765284e-10,-6.515152e-10)
# 2nd model 5 entries
model<-c('SDGVM','SDGVM','SDGVM','SDGVM','SDGVM', # 1st model
'TRIFFID','TRIFFID','TRIFFID','TRIFFID','TRIFFID') # 2nd model
latitude<-c(-34,-36,-39,-41,-44,-34,-36,-39,-41,-44)
color<-c('black','black','black','black','black',
'green','green','green','green','green')
input_df <-structure(list(flux = flux, model = model, lat = latitude,
color_plate=color),
.Names = c("flux","model", "lat","color_assigned"), row.names = c(NA, -10L),
class = "data.frame")
xlims=c(-50,-30) # x axis extent
custom_break<-seq(min(xlims),max(xlims),by=2)
theme_set(theme_bw(12))
chart <-ggplot(input_df, aes(x=lat, group=model, colour=model, fill=model)) +
geom_line(aes(y=flux), size=1.0) +
theme(legend.position='bottom') +
scale_x_continuous('Latitude',limits=xlims,breaks=custom_break) +
#custom breaks_to customize labels in x axis
scale_y_continuous(expression('Flux Difference')) +
scale_colour_discrete(name='', guide=guide_legend(nrow=4)) +
scale_fill_discrete(name='Model') +
geom_hline(aes(yintercept=0)) #to add black line at 0
print(chart)
(-1),請格式化您的文章。 – Arun
@阿倫 - 你友好的鄰居幫手在這裏幫助。 – thelatemail
@thelatemail,很高興,但我想你應該已經讓OP做到這一點。這是*這樣一個格式不好的帖子*!現在是時候爲問題做點努力了。 – Arun