6

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"))
Community
  • 1
  • 1
Shreta Ghimire
  • 1,019
  • 2
  • 13
  • 27
  • You need to add colour and shape to the `aes` specification. See [the documentation](http://docs.ggplot2.org/0.9.3.1/geom_point.html). – Lars Kotthoff Aug 06 '15 at 05:07
  • 1
    To the person who downvoted: Please provide some constructive feedback to accompany your vote. – bdemarest Aug 06 '15 at 06:14

1 Answers1

7

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.

Sarina
  • 548
  • 3
  • 10