Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the shape and color of the points with ggplot

Tags:

r

ggplot2

I am new to ggplot2. I have 2 different datasets whose values has to be plotted together in a graph. Looking at example of this question i tried using scale_shape_manual() and scale_color_manual(). But it doesn't change the shape and color of my points.

A small part of my code is as follows:

qplot(x=TempC7, y=PresshPa7) + 
 geom_point(aes(x=Temp, y=Pres), data=obsTemp1, na.rm=TRUE) +  
 scale_shape_manual(values=c(19,19)) + 
 scale_color_manual(values=c("blue", "red"))
like image 529
Shreta Ghimire Avatar asked Aug 06 '15 04:08

Shreta Ghimire


1 Answers

I would always prefer using the ggplot function instead of the qplot if you want to specify a lot of details. For your question it depends if you have your two datasets in one df or not. From the way of your example code I would say they are in one but I am not sure. Example code for plotting with data in one dataframe (df) that has a column called "Set" to define the two different sets:

ggplot(data=df,aes(x=Temp, y=Pres)) + 
     geom_point(aes(color=Set,shape=Set), na.rm=TRUE) +  
     scale_shape_manual(values=c(19,19)) + 
     scale_color_manual(values=c("blue", "red"))

Example code for plotting if your data are in two dataframes called "obsTemp1" and "obsTemp2":

ggplot() + 
     geom_point(data=obsTemp1,aes(x=Temp, y=Pres,color="blue",shape=19), na.rm=TRUE) + 
     geom_point(data=obsTemp2,aes(x=Temp, y=Pres,color="red",shape=19), na.rm=TRUE) 

Please keep in mind that by setting both values for shape to 19 you actually don't need to specify it.

like image 93
Sarina Avatar answered Oct 20 '22 15:10

Sarina