Re: [R] Problems with boxplot in ggplot2:qplot
Thanks a lot, Brian! -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1558810.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] Problems with boxplot in ggplot2:qplot
On 2/15/2010 2:41 PM, Dimitri Shvorob wrote: library(sqldf) library(ggplot2) t = data.frame(t = seq.Date(as.Date(2009-01-01), to = as.Date(2009-12-01), by = month)) x = data.frame(x = rnorm(5)) df = sqldf(select * from t, x) A simpler way to get random data that doesn't involve the sqldf package, and gets different x values for each date: df - data.frame(t = seq.Date(as.Date(2009-01-01), to=as.Date(2009-12-01), by=month), x=rnorm(60)) qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() You are converting your dates to a factor, so they are no longer dates. I'm guessing you did this to get a separate boxplot for each date, but that is not the right way to do that. Use the group aesthetic to make different groups. qplot(df$t, df$x, geom = boxplot, group=df$t) + theme_bw() qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() + scale_x_date(major = months, minor = weeks, format = %b) qplot(df$t, df$x, geom = boxplot, group=df$t) + theme_bw() + scale_x_date(major = months, minor = weeks, format = %b) qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() + scale_x_date(format = %b) qplot(df$t, df$x, geom = boxplot, group=df$t) + theme_bw() + scale_x_date(format = %b) -- Brian Diggs, Ph.D. Senior Research Associate, Department of Surgery, Oregon Health Science University __ 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] Problems with boxplot in ggplot2:qplot
Now that we have a reproducible example... ;) -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1557994.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] Problems with boxplot in ggplot2:qplot
Hi Dimitri, Have you looked at the examples for scale_x_date - http://had.co.nz/ggplot2/scale_date.html? They show you how to both set the limits and control the labels. Hadley On Sun, Feb 14, 2010 at 1:34 PM, Dimitri Shvorob dimitri.shvo...@gmail.com wrote: ... Unfortunately, a problem remains: I cannot label x ticks a la 'names.arg = '. month has values like '2009-01-01', '2009-02-01', etc., while I would prefer 'Jan', 'Feb'. Using closed$month = format(closed$month, %b) disrupts the order of plot's panels, which now follows the alphabetic order of month names. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1555358.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. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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] Problems with boxplot in ggplot2:qplot
Thank you, Hadley. I try jpeg(file, width = 800, height = 600, quality = 100) qplot(factor(closed$close.month), closed$closing.balance, geom = boxplot, main = Monthly distributions of closing balances, xlab = Month, ylab = Balance, USD) + theme_bw() + scale_x_date(major = months, minor = weeks, format = %b) dev.off() ('minor = ' can be skipped with no consequences, apparently). Labels disappear altogether. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1556571.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] Problems with boxplot in ggplot2:qplot
Trying + scale_x_date(format = %b) produces a peculiar result: Apr and Dec facets are labeled Jan, remaining labels are blank. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1556573.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] Problems with boxplot in ggplot2:qplot
Without a reproducible example, it's impossible to give you any more suggestions. Hadley On Mon, Feb 15, 2010 at 2:16 PM, Dimitri Shvorob dimitri.shvo...@gmail.com wrote: Trying + scale_x_date(format = %b) produces a peculiar result: Apr and Dec facets are labeled Jan, remaining labels are blank. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1556573.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. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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] Problems with boxplot in ggplot2:qplot
library(sqldf) library(ggplot2) t = data.frame(t = seq.Date(as.Date(2009-01-01), to = as.Date(2009-12-01), by = month)) x = data.frame(x = rnorm(5)) df = sqldf(select * from t, x) qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() + scale_x_date(major = months, minor = weeks, format = %b) qplot(factor(df$t), df$x, geom = boxplot) + theme_bw() + scale_x_date(format = %b) -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1556745.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] Problems with boxplot in ggplot2:qplot
Hi, it's hard to tell what's wrong without a reproducible example, but I noted two things: - AFAIK there is no plot method for ggplot2. You probably meant print(p) instead - if you map x to factor(month), I think it will be incompatible with your xlim values range(month). HTH, baptiste On 14 February 2010 19:55, Dimitri Shvorob dimitri.shvo...@gmail.com wrote: Dataframe closed contains balances of closed accounts: each row has month of closure (Date-type column month) and latest balance. I would like to plot by-month distributions of balances. A qplot call below produces several warnings and no output. Can anyone help? Thank you. PS. A really basic task, very similar to the examples on p. 71 of the ggplot2 book, apart from a Date grouping column; I am quite surprised to have problems with it. lattice package to the rescue? qplot(factor(month), balance, data = closed, geom = boxplot, xlim = range(closed$month)) There were 13 warnings (use warnings() to see them) warnings() Warning messages: 1: Removed 1 rows containing missing values (stat_boxplot). 2: Removed 7 rows containing missing values (geom_point). 3: Removed 5 rows containing missing values (geom_point). 4: Removed 8 rows containing missing values (geom_point). 5: Removed 3 rows containing missing values (geom_point). 6: Removed 5 rows containing missing values (geom_point). 7: Removed 2 rows containing missing values (geom_point). 8: Removed 12 rows containing missing values (geom_point). 9: Removed 2 rows containing missing values (geom_point). 10: Removed 1 rows containing missing values (geom_point). 11: Removed 2 rows containing missing values (geom_point). 12: Removed 3 rows containing missing values (geom_point). 13: Removed 4 rows containing missing values (geom_point). p = qplot(factor(month), balance, data = closed, geom = boxplot, xlim = range(closed$month)) plot(p) Error in plot.window(...) : need finite 'xlim' values -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1555338.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. __ 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] Problems with boxplot in ggplot2:qplot
... Unfortunately, a problem remains: I cannot label x ticks a la 'names.arg = '. month has values like '2009-01-01', '2009-02-01', etc., while I would prefer 'Jan', 'Feb'. Using closed$month = format(closed$month, %b) disrupts the order of plot's panels, which now follows the alphabetic order of month names. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1555358.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] Problems with boxplot in ggplot2:qplot
My bad: once I ran dev.off(), I did get a plot, albeit a blank one. Then I removed xlim - which I put in after qplot's complain about xlim - and voila! Thanks a lot. -- View this message in context: http://n4.nabble.com/Problems-with-boxplot-in-ggplot2-qplot-tp1555338p1555352.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.