Re: [R] ColorBrewer question
It works! Thanks a lot for your explanations, Michael. Good luck, Mario Von: R. Michael Weylandt michael.weyla...@gmail.com Cc: r-help@r-project.org r-help@r-project.org Gesendet: 5:22 Montag, 30.Januar 2012 Betreff: Re: [R] ColorBrewer question I believe you need to use the scale_fill_brewer since fill is the color of the bars while color is the outside of the bars in ggplot2-speak: E.g., with built-in data (it's polite to provide yours so that your minimal working example is working): data(diamonds) ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color = clarity)) # Note the borders are now changed but the fill is the same ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color = clarity)) + scale_color_brewer(pal = Blues) # Now the fill is changed, but you probably want to drop the border coloring since it's hideous against the blues ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color = clarity)) + scale_fill_brewer(pal = Blues) # So lovely ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity)) + scale_fill_brewer(pal = Blues) Michael Hello, R friends, I'm trying to change colors of my horizontal bars so that they show a sequence. I chose the ColorBrewer palette Blues. However the resulting plot doesn't show any changes to the default. I tried several places of + scale_colour_brewer(type=seq, pal = Blues) with no effect. This is my code: p - ggplot(data, aes(x = gender)) + scale_y_continuous(,formatter=percent) + xlab(Gender) + coord_flip() + scale_colour_brewer(type=seq, pal = Blues) p+geom_bar(aes(fill=pet),colour='black',position='fill') Any ideas welcome. Thanks, Mario [[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. [[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] Displaying percentages within bars
Hello, R friends, I've got this graph: p - ggplot(diamonds, aes(x = color)) + scale_fill_brewer(type=seq, pal = Blues) + scale_y_continuous(,formatter=percent) + coord_flip() p+geom_bar(aes(fill=cut),colour='black',position='fill') Is it possible to place percentages within each field of the bars? So, for instance, the dark blue field of color = D would contain a number of about 42.0%. A second question is how to change the size of this number. Any comments are welcome! Mario [[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] ColorBrewer question
Hello, R friends, I'm trying to change colors of my horizontal bars so that they show a sequence. I chose the ColorBrewer palette Blues. However the resulting plot doesn't show any changes to the default. I tried several places of + scale_colour_brewer(type=seq, pal = Blues) with no effect. This is my code: p - ggplot(data, aes(x = gender)) + scale_y_continuous(,formatter=percent) + xlab(Gender) + coord_flip() + scale_colour_brewer(type=seq, pal = Blues) p+geom_bar(aes(fill=pet),colour='black',position='fill') Any ideas welcome. Thanks, Mario [[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] Horizontal stacked 100% bars with ggplot2
Thanks, Carlos, your solution looks nice, however, there are 4 bars instead of 2 i.e. bars are not stacked. Meanwhile I got a solution for that task. So thanks for sharing your version of it! Good luck, Mario Von: Carlos Ortega c...@qualityexcellence.es Cc: r-help@r-project.org r-help@r-project.org Gesendet: 23:02 Samstag, 28.Januar 2012 Betreff: Re: [R] Horizontal stacked 100% bars with ggplot2 Hello, If it helps...: Lines - pet gender dog male dog female dog male cat female cat female cat male d.f - read.table(textConnection(Lines), header=T, as.is = TRUE) d.tab-table(d.f$pet, d.f$gender) d.f.tab-as.data.frame(table(d.f$pet, d.f$gender)) names(d.f.tab)-c('pet','gender', 'Freq') library(lattice) histogram( ~ Freq | pet *gender, data=d.f.tab, groups=gender, stack=T, horizontal=T ) Regards, Carlos Ortega www.qualityexcellence.es Hello, R friends, I'm trying to crack this nut: Example Data. pet gender dog male dog female dog male cat female cat female cat male Plot Task. Horizontal 100% bars where y axis shows gender factor (male vs. female) and x axis shows percentage of kind of pets (dog vs. cat) so that % dogs + % cats are stacked in 1 bar and sum up to 100% (for each gender group 1 bar). How can this be done with ggplot2? [[elided Yahoo spam]] Mario [[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. [[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] Horizontal stacked 100% bars with ggplot2
Hello, R friends, I'm trying to crack this nut: Example Data. pet gender dog male dog female dog male cat female cat female cat male Plot Task. Horizontal 100% bars where y axis shows gender factor (male vs. female) and x axis shows percentage of kind of pets (dog vs. cat) so that % dogs + % cats are stacked in 1 bar and sum up to 100% (for each gender group 1 bar). How can this be done with ggplot2? Thanks for any comments! Mario [[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] pretty(range(data$z),10) Error
Hello, R-List, I'm getting error messages when adding geom_density2d() [package ggplot2]: Fehler in pretty(range(data$z), 10) : NA/NaN/Inf in externem Funktionsaufruf (arg 1) Zusätzlich: Warnmeldungen: 1: Removed 1 rows containing missing values (stat_contour). 2: In min(x) : kein nicht-fehlendes Argument für min; gebe Inf zurück 3: In max(x) : kein nicht-fehlendes Argument für max; gebe -Inf zurück 4: In min(x) : kein nicht-fehlendes Argument für min; gebe Inf zurück 5: In max(x) : kein nicht-fehlendes Argument für max; gebe -Inf zurück I installed 2.11.1 Patched in the hope to overcome this obstacle but in vain. I tried reading spss and csv format - no effect. While this one works: ggplot(sp2, aes(x=Qq04, y=Qq01)) + geom_point() + facet_wrap(~ segment,ncol=3) This one fails: ggplot(sp2, aes(x=Qq04, y=Qq01)) + geom_point() + facet_wrap(~ segment,ncol=3) + geom_density2d() But it only fails for 2 out of 10 x-variables, although they do not differ in structure. Data structure looks like this: segment Qq01 Qq02 Qq02a Qq04 Qq05 Qq07 Qq08 Qq10 Qq11 Qq15 Qq17a A 7 5 5 5 5 4 5 5 3 7 7 A 5 4 4 3 4 3 4 4 4 5 6 B 3 3 3 3 2 3 4 2 4 3 2 B 6 4 5 3 3 3 4 4 3 6 6 C 3 3 3 3 3 4 2 3 3 4 2 C 2 1 4 3 1 4 1 1 3 4 2 D 5 3 4 3 3 3 4 3 3 6 3 D 5 3 4 2 2 4 4 3 3 4 4 E 3 3 3 2 3 4 4 3 2 3 4 E 7 5 5 5 5 4 4 5 1 7 7 F 6 5 4 3 3 3 4 3 3 6 6 F 5 3 4 3 3 4 4 3 3 4 4 G 4 3 3 3 2 1 3 3 3 4 4 G 6 5 5 5 5 4 5 5 3 7 7 H 6 5 5 4 4 4 5 4 3 5 6 H 7 5 5 5 4 4 5 5 3 7 7 I 6 5 5 4 4 4 5 4 3 6 6 I 6 3 4 2 3 4 4 3 4 6 4 J 5 3 4 1 3 4 4 3 3 5 5 J 4 2 4 3 2 2 3 2 3 4 4 K 4 4 4 2 3 4 4 4 3 5 5 K 6 4 3 3 2 3 4 3 3 6 5 L 6 4 5 3 3 4 5 4 3 6 6 L 3 1 2 2 1 3 3 1 3 4 4 ... About 1.800 cases (more than 100 per segment). Did anybody experience similar problems? Thanks for all comments, Mario [[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] Reply on ggplot2 - tricky problem
That comes really close to what I had in mind. Thanks a lot for helping out, Justin! Good luck, Mario Re: [R] ggplot2 - tricky problem how bout: dat-data.frame(id=1:4,city=c('berlin','munich'),likeability=c(5,4,6,5),uniqueness=c(3,4,4,4)) ggplot(ddply(melt(dat, id.vars=c('id','city')), .(variable,city), summarise, value=mean(value)), aes(x=factor(city),y=value)) + geom_point() + facet_wrap(~variable) the line drawing is a bit more tricky... Since the x values are factors rather than continuous, fitting a line to them is kind of nonsense. It matters which order they are in for example. If instead you want to plot something like: ggplot(dat,aes(x=likeability,y=uniqueness,colour=city))+geom_point()+geom_smooth(aes(group=city),method='lm') You could draw fit lines that make a bit more sense. Forgive me if I'm over simplifying your problem! Justin On Thu, Jan 5, 2012 at 7:46 AM, Mario Giesel rr.gie...@yahoo.de wrote: Hello, R friends, I've been struggling quite a bit with ggplot2. Having worked through Hadleys book twice I still wonder how to solve this task. 1. Short example Dataframe: id city Likeability Uniqueness 1 Berlin 5 3 2 Munich 4 4 3 Berlin 6 4 4 Munich 5 4 2. Task: a) Facetting plots for each attitude (1 plot for likeability and uniqueness each, horizontally on one page) b) Showing Berlin and Munich together on x axis c) Showing the means of Berlin and Munich on y axis (means of cities in likeability on first plot, means of cities in uniqueness on second plot) d) Drawing a line through mean points on each plot Hope I could explain it understandably. Any help is appreciated! Thanks a lot, Mario [[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. Antwort an: Antwort an Justin Haynes Senden [[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] ggplot2 - tricky problem
Hello, R friends, I've been struggling quite a bit with ggplot2. Having worked through Hadleys book twice I still wonder how to solve this task. 1. Short example Dataframe: id city Likeability Uniqueness 1 Berlin 5 3 2 Munich 4 4 3 Berlin 6 4 4 Munich 5 4 2. Task: a) Facetting plots for each attitude (1 plot for likeability and uniqueness each, horizontally on one page) b) Showing Berlin and Munich together on x axis c) Showing the means of Berlin and Munich on y axis (means of cities in likeability on first plot, means of cities in uniqueness on second plot) d) Drawing a line through mean points on each plot Hope I could explain it understandably. Any help is appreciated! Thanks a lot, Mario [[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] Filling a variable with unmentioned categories
Hello, list, I've been struggling with this task for a while looking for an efficient way to solve it: There are two variables 'price' and 'mentioned'. I want to 'enlarge' data so that missing price points within the price range are added to variable price. Also variable 'mentioned' is to receive values 0 in these cases. Note: Price points in original data can repeat if several persons mentioned that price point. Example: a) Original data: price mentioned 0,00 1 0,00 1 0,02 1 0,03 1 0,03 1 0,04 1 0,10 1 0,16 1 0,19 1 0,19 1 price range is 0,00 - 0,19. Some prices are missing, e.g. 0,01 . b) Supplemented data: price mentioned 0,00 1 0,00 1 0,01 0 0,02 1 0,03 1 0,03 1 0,04 1 0,05 0 0,06 0 0,07 0 0,08 0 0,09 0 0,10 1 0,11 0 0,12 0 0,13 0 0,14 0 0,15 0 0,16 1 0,17 0 0,18 0 0,19 1 0,19 1 0,20 0 Any ideas are welcome. Thanks a lot, Mario Aachen, Germany [[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] Numerical Format on axis
Thoiusand thanks to David and Don. Great help! Mario Aachen, Germany Von: MacQueen, Don macque...@llnl.gov Cc: r-help@r-project.org r-help@r-project.org; David Winsemius dwinsem...@comcast.net Gesendet: 2:30 Donnerstag, 17.November 2011 Betreff: Re: [R] Numerical Format on axis To add to what David suggests, and since you're new to R, something like this: plot(x,y, yaxt='n') yticks - pretty(y) axis(2, at=yticks, labels=sprintf(%1.2f,yticks)) See the help page for par ?par and look for the entry for 'xaxt' to see what the 'yaxt' arg to plot does. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/16/11 6:35 AM, David Winsemius dwinsem...@comcast.net wrote: On Nov 16, 2011, at 7:41 AM, Mario Giesel wrote: Hello, list, I'm new to R and I'm trying to produce a chart with currency values on the y axis. Values should be e.g. 1,00, 1,50, 2,00, etc. In fact they are 1,0, 1,5, 2,0, etc. How do I get R to show two digits after the comma on that axis? ?sprintf ?format On the left (geographic) side of the Atlantic, it might be: sprintf(%1.2f, 1) [1] 1.00 I assume that your system is set up with different options() and that your punkts are going to be handle to your liking by sprintf. -- David Winsemius, MD West Hartford, CT __ 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. On the left (geographic) side of the Atlantic, it might be: sprintf(%1.2f, 1) [1] 1.00 I assume that your system is set up with different options() and that your punkts are going to be handle to your liking by sprintf. -- David Winsemius, MD West Hartford, CT [[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] Numerical Format on axis
Hello, list, I'm new to R and I'm trying to produce a chart with currency values on the y axis. Values should be e.g. 1,00, 1,50, 2,00, etc. In fact they are 1,0, 1,5, 2,0, etc. How do I get R to show two digits after the comma on that axis? Thanks for any help, Mario [[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.