Re: [R] Multi-panel Pie Charts.
Hi Jim, what's the tab.title function you are using? - Try http://prettygraph.com Pretty Graph , the easiest way to make R-powered graphs on the web. -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1690627.html Sent from the R help mailing list archive at Nabble.com. __ 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] Multi-panel Pie Charts.
On 03/26/2010 12:41 AM, Hrishi Mittal wrote: Hi Jim, what's the tab.title function you are using? It's in the plotrix package. The panes function will be in the next version. Jim __ 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] Multi-panel Pie Charts.
Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 R Code: as it is from the book, library(lattice) library(grid) library(gridBase) panel.piechart - function(x, y, labels = as.character(y), edges = 200, radius = 0.8, clockwise = FALSE, init.angle = if(clockwise) 90 else 0, density = NULL, angle = 45, col = superpose.polygon$col, border = superpose.polygon$border, lty = superpose.polygon$lty, ...) { stopifnot(require(gridBase)) superpose.polygon - trellis.par.get(superpose.polygon) opar - par(no.readonly = TRUE) on.exit(par(opar)) if (panel.number() 1) par(new = TRUE) par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0)) pie(as.numeric(x), labels = labels, edges = edges, radius = radius, clockwise = clockwise, init.angle = init.angle, angle = angle, density = density, col = col, border = border, lty = lty) } piechart - function(x, data = NULL, panel = panel.piechart, ...) { ocall - sys.call(sys.parent()) ocall[[1]] - quote(piechart) ccall - match.call() ccall$data - data ccall$panel - panel ccall$default.scales - list(draw = FALSE) ccall[[1]] - quote(lattice::barchart) ans - eval.parent(ccall) ans$call - ocall ans } ## Figure 14.5 par(new = TRUE) piechart(foo) Thanks in advance, Gurmeet [[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] Multi-panel Pie Charts.
Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.html Sent from the R help mailing list archive at Nabble.com. __ 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] Multi-panel Pie Charts.
Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, ~Gurmeet On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote: Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.html Sent from the R help mailing list archive at Nabble.com. __ 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.htmlhttp://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.
Re: [R] Multi-panel Pie Charts.
Gurmeet and I are looking for such utility. It could be helpful! On Wed, Mar 24, 2010 at 3:46 PM, Gary Miller mail2garymil...@gmail.comwrote: Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, ~Gurmeet On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote: Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Would paneled bar charts not suffice? I don't mean to be harsh, but the only situation I can think of where I would consider a pie chart would be if I wanted to take advantage of the fact that people are worse at judging differences in area than they are at judging differences in length in order to hide some trend in my data. Anyway, the following code uses ggplot2 to produce a paneled bar plot from your data: require( ggplot2 ) productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label = c(Apr, Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names = c(variable, month, value), class = data.frame, row.names = c(NA, -16L)) productPlot - qplot( variable, value, data = productData, geom = 'bar', xlab = 'Product', ylab = 'Percentage' ) + facet_wrap( ~ month ) + theme_bw() print( productPlot ) I know it's not what you want, but I personally need a strong argument for generating pie charts before I would perpetuate their use. Gurmeet wrote: 1. Is anyone aware of some in-built script/function which can do this for me. I'm aware of one given in Deepayan's book, but anything apart from this? 2. I tried using Deepayan's script on following data set but it doesn't seem to work as expected - labels are getting repeated/overlapping. I'm really not sure what could be the problem, can anyone help please. I hope data is in the right format, as expected. Data read into object foo: variable month value ProdA Jan25 ProdA Feb30 ProdA Mar25 ProdA Apr10 ProdB Jan25 ProdB Feb30 ProdB Mar50 ProdB Apr40 ProdC Jan40 ProdC Feb30 ProdC Mar20 ProdC Apr40 ProdD Jan10 ProdD Feb10 ProdD Mar 5 ProdD Apr10 {SNIP} Thanks in advance, Gurmeet Providing data as a printed table, like you did, is not the most effective way to transmit example data on this list. There are two major disadvantages: * Tabulated data often gets mangled in email * Tabulated data can not be copied and pasted directly into R to regenerate the example data.frame- it takes me ~4 minutes of mucking around with Excel to regenerate a .csv file that R can ingest. This added time will limit the number of people who will attempt to investigate your problem. The best way to transmit the contents of a data frame is to paste the output of the dput() function. This function dumps the data frame to an R command that can be simply copied and pasted into a R session to regenerate the data.frame. The results of dput is the structure() command I used in my example above. Hope this helps in some way! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.html Sent from the R help mailing list archive at Nabble.com. __ 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.htmlhttp://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.
Re: [R] Multi-panel Pie Charts.
Gary Miller wrote: Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, Well, if the management trolls *DEMAND* pie, then these sites provide a good start with ggplot2: http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/ http://had.co.nz/ggplot2/coord_polar.html Using the data I posted before, you could apply those approach with: productPie - qplot( factor(1), value/100, data = productData, geom = 'bar', fill = variable, xlab = '', ylab = '' ) + facet_wrap( ~ month, scales = 'free_y' ) + coord_polar( theta = 'y' ) + scale_y_continuous( formatter = 'percent' ) + theme_bw() print( productPie ) The beauty of ggplot2 is that that is basically the same chart I posted last time, the bars have just been bent into a pie through the use of coord_polar(). It probably needs some fine-tuning, but I'll leave that up to you. Good luck! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.html Sent from the R help mailing list archive at Nabble.com. __ 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] Multi-panel Pie Charts.
On 03/25/2010 06:00 AM, Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Hi Gurmeet, Your message prompted me to finish a little function that I had almost forgotten. panes-function(nrow=2,ncol=2,mar=c(0,0,1.6,0),oma=c(2,1,1,1)) { oldpar-par(mar,mfrow,oma) par(mfrow=c(nrow,ncol),mar=mar,oma=oma) return(oldpar) } oldpar-panes() pie(foo$value[foo$month==Jan],labels=foo$variable[foo$month==Jan], radius=0.7) tab.title(January sales,tab.col=#66) box() pie(foo$value[foo$month==Feb],labels=foo$variable[foo$month==Feb], radius=0.7) tab.title(February sales,tab.col=#66) box() pie(foo$value[foo$month==Mar],labels=foo$variable[foo$month==Mar], radius=0.7) tab.title(March sales,tab.col=#66) box() pie(foo$value[foo$month==Apr],labels=foo$variable[foo$month==Apr], radius=0.7) tab.title(April sales,tab.col=#66) box() par(xpd=TRUE) mtext(First quarter sales,at=-1.2,line=0.8,side=1,cex=1.5) par(xpd=FALSE) par(oldpar) Is this what you wanted? Jim __ 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] Multi-panel Pie Charts.
Hi Jim, exactly what we are expecting. Thanks a lot for your efforts... it should be really helpful! On Wed, Mar 24, 2010 at 10:50 PM, Jim Lemon j...@bitwrit.com.au wrote: On 03/25/2010 06:00 AM, Gurmeet wrote: Hi All, I'm trying to find out a way to plot multi-panel pie charts. It may not be the best way to present data, but I would still need one. Hi Gurmeet, Your message prompted me to finish a little function that I had almost forgotten. panes-function(nrow=2,ncol=2,mar=c(0,0,1.6,0),oma=c(2,1,1,1)) { oldpar-par(mar,mfrow,oma) par(mfrow=c(nrow,ncol),mar=mar,oma=oma) return(oldpar) } oldpar-panes() pie(foo$value[foo$month==Jan],labels=foo$variable[foo$month==Jan], radius=0.7) tab.title(January sales,tab.col=#66) box() pie(foo$value[foo$month==Feb],labels=foo$variable[foo$month==Feb], radius=0.7) tab.title(February sales,tab.col=#66) box() pie(foo$value[foo$month==Mar],labels=foo$variable[foo$month==Mar], radius=0.7) tab.title(March sales,tab.col=#66) box() pie(foo$value[foo$month==Apr],labels=foo$variable[foo$month==Apr], radius=0.7) tab.title(April sales,tab.col=#66) box() par(xpd=TRUE) mtext(First quarter sales,at=-1.2,line=0.8,side=1,cex=1.5) par(xpd=FALSE) par(oldpar) Is this what you wanted? Jim [[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] Multi-panel Pie Charts.
Thanks Charlie... I think its worth exploring ggplot2 functionality. On Wed, Mar 24, 2010 at 4:06 PM, Sharpie ch...@sharpsteen.net wrote: Thanks for your reply Sharpie. I completely understand that it may not be the best to go with muti-panel pie charts, but my group would like to have this utility along with barplot/dotplot (may be, using it for proportions data). Thanks, Well, if the management trolls *DEMAND* pie, then these sites provide a good start with ggplot2: http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/ http://had.co.nz/ggplot2/coord_polar.html Using the data I posted before, you could apply those approach with: productPie - qplot( factor(1), value/100, data = productData, geom = 'bar', fill = variable, xlab = '', ylab = '' ) + facet_wrap( ~ month, scales = 'free_y' ) + coord_polar( theta = 'y' ) + scale_y_continuous( formatter = 'percent' ) + theme_bw() print( productPie ) The beauty of ggplot2 is that that is basically the same chart I posted last time, the bars have just been bent into a pie through the use of coord_polar(). It probably needs some fine-tuning, but I'll leave that up to you. Good luck! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.html Sent from the R help mailing list archive at Nabble.com. __ 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.htmlhttp://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.