Change the shape and color of the points with ggplot
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.
Related videos on Youtube
Shreta Ghimire
Updated on September 15, 2022Comments
-
Shreta Ghimire over 1 year
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()
andscale_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"))
-
bdemarest over 8 yearsTo the person who downvoted: Please provide some constructive feedback to accompany your vote.
-
-
Shreta Ghimire over 8 yearsThis helps a lot. Thank you. And yes I have different dataframes. :)