[R] ggplot and colors
Hello, I have a problem with ggplot and colors I used this function to draw somes lines and I want them to be all black (just to test) however, I dont get any black line in the figure. Do you have any experience with ggplot and manual colors?? ggplot(cmax, aes(cmax[,3], cmax[,6],colour=interaction(cmax[,1],cmax[,2]))) + geom_line() + geom_point() + scale_fill_manual(values=c(black, black , black, black, black, black, black, black, black, black, black, black )) best regards -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 attachment: test.png__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot and colors
Hi, fill is not the same as color. You need scale_color_manual(values=c(black, black , black, black, black, black, black, black, black, black, black, black )) although it is not clear why you are using aesthetic mapping to set everything to black... Best, Ista On Mon, Feb 4, 2013 at 6:17 AM, Adel ESSAFI adeless...@gmail.com wrote: Hello, I have a problem with ggplot and colors I used this function to draw somes lines and I want them to be all black (just to test) however, I dont get any black line in the figure. Do you have any experience with ggplot and manual colors?? ggplot(cmax, aes(cmax[,3], cmax[,6],colour=interaction(cmax[,1],cmax[,2]))) + geom_line() + geom_point() + scale_fill_manual(values=c(black, black , black, black, black, black, black, black, black, black, black, black )) best regards -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot pale colors
Hi Ista, Thank you so much for your explanation!! I know now how to handle this scale_color_manual() function. Le 28/05/2011 19:56, Ista Zahn a écrit : Hi Victor, The problem is that you have not grasped the difference between setting an aesthetic to a fixed value and mapping it to a variable. See below for details. On Sat, May 28, 2011 at 6:16 AM, Victor Gabillon victor.gabil...@inria.fr wrote: Hello i am new to ggplot and i observed a strange behavior. I want to display two groups of points, each group with a different color. But i encountered a problem with the colors. Here is a first example: dataset- data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ),colour=blue)+geom_hline(aes(yintercept=0.25),colour='blue', size=2) with this code all the point are blue (like the line below) But if i try the following code, where my goal is to have the point on the left blue and the one on the right red, a problem appears: dataset- data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ,colour=c(blue,blue,red,red)))+geom_hline(aes(yintercept=0.25),colour='blue', size=2) The colors are not coming from c(blue, blue, red, red). Try this to see p- ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x) + geom_point(aes(shape = c(16,16,15,15) ,colour=c(purple,purple,foo,foo)), size = 6) + geom_hline(aes(yintercept=0.25),colour='blue', size=2) p So now you see that you are not setting the colors to be red and blue, you are mapping the color to a variable that just happens to have levels red and blue. The actual colors that are mapped to that variable are determined by scale_colour_discrete, as you can see from p + scale_color_manual(value=c(red, blue)) p + scale_color_manual(value=c(green, black)) As a general rule, if you want an aesthetic (e.g., color, size, shape etc.) to vary (i.e., to have more than one value) you should put it as an argument to aes(). If you just want to set it to a fixed value you should set it as an argument to geom_* or as an argument to ggplot() itself. The points have different colors but those colors are pale (dull). You can see it by comparing the blue of the points to the blue of the line. I guessing i am duing it wrong but i'm stucked with it. Do you have suggestions? An additional question is that i want to add text along the blue line (which is a reference) but i did not understand what geom_text was expecting. see http://had.co.nz/ggplot2/geom_text.html Best, Ista Thanks for your help! Victor [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ggplot pale colors
Hello i am new to ggplot and i observed a strange behavior. I want to display two groups of points, each group with a different color. But i encountered a problem with the colors. Here is a first example: dataset - data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ),colour=blue)+geom_hline(aes(yintercept=0.25),colour='blue', size=2) with this code all the point are blue (like the line below) But if i try the following code, where my goal is to have the point on the left blue and the one on the right red, a problem appears: dataset - data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ,colour=c(blue,blue,red,red)))+geom_hline(aes(yintercept=0.25),colour='blue', size=2) The points have different colors but those colors are pale (dull). You can see it by comparing the blue of the points to the blue of the line. I guessing i am duing it wrong but i'm stucked with it. Do you have suggestions? An additional question is that i want to add text along the blue line (which is a reference) but i did not understand what geom_text was expecting. Thanks for your help! Victor [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot pale colors
Hi Victor, The problem is that you have not grasped the difference between setting an aesthetic to a fixed value and mapping it to a variable. See below for details. On Sat, May 28, 2011 at 6:16 AM, Victor Gabillon victor.gabil...@inria.fr wrote: Hello i am new to ggplot and i observed a strange behavior. I want to display two groups of points, each group with a different color. But i encountered a problem with the colors. Here is a first example: dataset - data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ),colour=blue)+geom_hline(aes(yintercept=0.25),colour='blue', size=2) with this code all the point are blue (like the line below) But if i try the following code, where my goal is to have the point on the left blue and the one on the right red, a problem appears: dataset - data.frame(Main = c(A, A, B, B), Detail = c( b, c, 1, 2), resp = runif(4, min = 0.5, max = 1)) ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x)+ geom_point(aes( size=6,shape = c(16,16,15,15) ,colour=c(blue,blue,red,red)))+geom_hline(aes(yintercept=0.25),colour='blue', size=2) The colors are not coming from c(blue, blue, red, red). Try this to see p - ggplot(dataset, aes(x = Detail, y = resp)) + facet_grid(.~Main, scales = free_x) + geom_point(aes(shape = c(16,16,15,15) ,colour=c(purple,purple,foo,foo)), size = 6) + geom_hline(aes(yintercept=0.25),colour='blue', size=2) p So now you see that you are not setting the colors to be red and blue, you are mapping the color to a variable that just happens to have levels red and blue. The actual colors that are mapped to that variable are determined by scale_colour_discrete, as you can see from p + scale_color_manual(value=c(red, blue)) p + scale_color_manual(value=c(green, black)) As a general rule, if you want an aesthetic (e.g., color, size, shape etc.) to vary (i.e., to have more than one value) you should put it as an argument to aes(). If you just want to set it to a fixed value you should set it as an argument to geom_* or as an argument to ggplot() itself. The points have different colors but those colors are pale (dull). You can see it by comparing the blue of the points to the blue of the line. I guessing i am duing it wrong but i'm stucked with it. Do you have suggestions? An additional question is that i want to add text along the blue line (which is a reference) but i did not understand what geom_text was expecting. see http://had.co.nz/ggplot2/geom_text.html Best, Ista Thanks for your help! Victor [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.