Skip to content

Instantly share code, notes, and snippets.

@2sbsbsb
Created June 9, 2012 00:07
Show Gist options
  • Save 2sbsbsb/2898763 to your computer and use it in GitHub Desktop.
Save 2sbsbsb/2898763 to your computer and use it in GitHub Desktop.
How to draw a line with different color and size
library("ggplot2")
> x = c(1:10)
> y = c(1:10)
> colours = rainbow(10)
> size <- c(1,2,3,4,5,5,4,3,2,1)
> tt <- data.frame(x=x,y=y,colours=colours,size=size)
> tt
x y colours size
1 1 1 #FF0000FF 1
2 2 2 #FF9900FF 2
3 3 3 #CCFF00FF 3
4 4 4 #33FF00FF 4
5 5 5 #00FF66FF 5
6 6 6 #00FFFFFF 5
7 7 7 #0066FFFF 4
8 8 8 #3300FFFF 3
9 9 9 #CC00FFFF 2
10 10 10 #FF0099FF 1
> ggplot(tt,aes(x=x,y=y,group=1,colour=colours,size=size)) + geom_line()
# The most important thing to remember is group=1 which meant all the points belongs to just one group.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment