Adjusting the width of legend for continuous variable

前端 未结 2 1377
栀梦
栀梦 2020-12-10 12:33

I have a script below to illustrate my question:

temp.df <- data.frame(x=1:100,y=1:100,z=1:100,stringsAsFactors=FALSE)
chart <- ggplot(data=temp.df,aes         


        
2条回答
  •  我在风中等你
    2020-12-10 13:06

    Instead of function guides() you should use the function theme() and set the legend.key.width=

    temp.df <- data.frame(x=1:100,y=1:100,z=1:100,stringsAsFactors=FALSE)
    chart <- ggplot(data=temp.df,aes(x=x,y=y))
    chart <- chart + geom_line(aes(colour=z))
    chart <- chart + scale_colour_continuous(low="blue",high="red")
    chart <- chart + theme(legend.position="bottom")
    chart <- chart + theme(legend.key.width=unit(3,"cm"))
    

提交回复
热议问题