Mary Kindall
2012-Jan-16 19:01 UTC
[R] ggplot- using geom_point and geom_line at the same time
Hi I am plotting line chart using ggplot and want to use geom_line and geom_point simultaneously. I get the plot but now I have two legends. None of the legend is representing the true values. I need the legend with shape and color both. Thanks> con = textConnection("inputs var1 var2 var3+ 100 10 5 2+ 1000 20 10 4+ 5000 30 15 8+ 10000 40 20 16+ 30000 50 25 32")> data = read.table(con, header=TRUE)> data inputs var1 var2 var31 100 10 5 2 2 1000 20 10 4 3 5000 30 15 8 4 10000 40 20 16 5 30000 50 25 32> data = melt(data, id="inputs")> data inputs variable value 1 100 var1 10 2 1000 var1 20 3 5000 var1 30 4 10000 var1 40 5 30000 var1 50 6 100 var2 5 7 1000 var2 10 8 5000 var2 15 9 10000 var2 20 10 30000 var2 25 11 100 var3 2 12 1000 var3 4 13 5000 var3 8 14 10000 var3 16 15 30000 var3 32> g <- ggplot(data,aes(x=inputs, value, colour=variable, fill = variable))> g <- g + geom_point(aes(shape=variable), size=3) > g <- g + geom_line(lwd=1) + ylab("time") + xlab("inputs") + labs(colour="MyLegend", fill "MyLegend")> g [[alternative HTML version deleted]]
Mary Kindall
2012-Jan-16 21:14 UTC
[R] ggplot- using geom_point and geom_line at the same time
Hi I am plotting line chart using ggplot and want to use geom_line and geom_point simultaneously. I want to rename my legend but uptonow I remain unsuccessful. Someone please point what to add for renaming the legend. I attached my example below. Thanks con = textConnection("inputs var1 var2 var3 100 10 5 2 1000 20 10 4 5000 30 15 8 10000 40 20 16 30000 50 25 32") data = read.table(con, header=TRUE) data data = melt(data, id="inputs") g <- ggplot(data,aes(x=inputs, value, colour= variable, fill = variable, shape=variable)) g <- g + geom_line(lwd=0.8) g <- g + geom_point() g <- g + scale_x_continuous(name='Number of inputs') g <- g + scale_y_continuous('Conversion time (sec.)') g -- ------------- Mary Kindall Yorktown Heights, NY USA [[alternative HTML version deleted]]