|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
ggplot2: font size mismatch for pdf outputHi
In the following, the graph I see on the screen and the .png output coincide. However, in the .pdf file, the fonts seem to be scaled fairly larger, resulting in the label for the top legend disappearing. Is this an infelicity or bug, or is there something I've missed? More generally, how do I control the size of fonts used in legends and axis labels? library(car) library(ggplot2) qp <-qplot (education , income , shape=type , size=women , colour=prestige , xlab="Education" , ylab="Income", data=Prestige) + scale_y_continuous(limits=c(NA, 20000)) qp + scale_size(to=c(1,8)) ggsave(file="prestige-ggplot.png", width=6, height=5) # OK ggsave(file="prestige-ggplot.pdf", width=6, height=5) # fonts too large -Michael ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf outputWhat version of R and OS is this? Prior to R 2.7.0 there was little
attempt to match output dimensions from various devices, and one of the png devices in 2.7.0 has an error in doing so, fixed in R-patched (see NEWS). On Mon, 12 May 2008, Michael Friendly wrote: > Hi > > In the following, the graph I see on the screen and the .png output > coincide. However, in the .pdf file, the fonts seem to be scaled > fairly larger, resulting in the label for the top legend disappearing. > Is this an infelicity or bug, or is there something I've missed? > > More generally, how do I control the size of fonts used in legends > and axis labels? > > library(car) > library(ggplot2) > > qp <-qplot (education , income , shape=type , size=women , colour=prestige , > xlab="Education" , ylab="Income", data=Prestige) > + scale_y_continuous(limits=c(NA, 20000)) Hmm, you can't break the line before '+'. > qp + scale_size(to=c(1,8)) > > ggsave(file="prestige-ggplot.png", width=6, height=5) # OK > ggsave(file="prestige-ggplot.pdf", width=6, height=5) # fonts too large I would not expect you to be able to specify a smaller size without also reducing 'pointsize'. E.g. dev.print() does so, but ggsave seems not to. > -Michael > > ______________________________________________ > R-help@... 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. > -- Brian D. Ripley, ripley@... Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf outputSorry for not providing this in my initial posting.
I'm using R version 2.7.0 (2008-04-22), on Win XP Pro. As I said, the .png output matched what I saw on screen. It was the .pdf output for which the font size was noticeably larger, enough to make the legend run off the screen. -Michael Prof Brian Ripley wrote: > What version of R and OS is this? Prior to R 2.7.0 there was little > attempt to match output dimensions from various devices, and one of the > png devices in 2.7.0 has an error in doing so, fixed in R-patched (see > NEWS). > > On Mon, 12 May 2008, Michael Friendly wrote: > >> Hi >> >> In the following, the graph I see on the screen and the .png output >> coincide. However, in the .pdf file, the fonts seem to be scaled >> fairly larger, resulting in the label for the top legend disappearing. >> Is this an infelicity or bug, or is there something I've missed? >> >> More generally, how do I control the size of fonts used in legends >> and axis labels? >> >> library(car) >> library(ggplot2) >> >> qp <-qplot (education , income , shape=type , size=women , >> colour=prestige , >> xlab="Education" , ylab="Income", data=Prestige) >> + scale_y_continuous(limits=c(NA, 20000)) > > Hmm, you can't break the line before '+'. > >> qp + scale_size(to=c(1,8)) >> >> ggsave(file="prestige-ggplot.png", width=6, height=5) # OK >> ggsave(file="prestige-ggplot.pdf", width=6, height=5) # fonts too large > > I would not expect you to be able to specify a smaller size without also > reducing 'pointsize'. E.g. dev.print() does so, but ggsave seems not to. > >> -Michael >> >> ______________________________________________ >> R-help@... 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. >> > -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf output> More generally, how do I control the size of fonts used in legends
> and axis labels? There is no general way (yet) - it is on my customisation to do list, which I hope to make progress on over summer. Hadley -- http://had.co.nz/ ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf outputWhat you can do is change the parameter "pointsize" when creating the
device. See ?pdf. It will change the size of all texts (labels, legend, title...) at the same time. I tried it with png, it works quite well (provided you use the latest versions of everything, including cairo, I think). Xavier hadley wickham a écrit : >> More generally, how do I control the size of fonts used in legends >> and axis labels? >> > > There is no general way (yet) - it is on my customisation to do list, > which I hope to make progress on over summer. > > Hadley > > -- Xavier Chardon Thésard Institut de l'élevage / INRA Projet ACTA "modélisation environnementale des systèmes bovins et porcins" xavier.chardon@... xavier.chardon@... 02 23 48 50 91 ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf outputIf I do
> windows(width=6, height=5) then the pdf plot is very good copy of what I see on screen. So the main issue seems to be that you changed the device size when you asked for the save. If you do that, you need to change 'pointsize' too -- but as you changed the aspect ratio, you cannot make that work exactly. There is a bug in ggsave() for bitmap devices: it computes the width and height from 'dpi', but it fails to pass that information on to the devices, which assume 72dpi. So what it actually asked for was a 8 x 6.67 inch plot at 72dpi. 72dpi would be a better default, as not all of the many bitmap devices work correctly at other resolutions (and none did prior to R 2.7.0). If you want an accurate png copy of what you see on screen, use savePlot() or the device menus. That copies the backing bitmap. On Mon, 12 May 2008, Michael Friendly wrote: > Sorry for not providing this in my initial posting. > I'm using R version 2.7.0 (2008-04-22), on Win XP Pro. > > As I said, the .png output matched what I saw on screen. > It was the .pdf output for which the font size was noticeably > larger, enough to make the legend run off the screen. > > -Michael > > Prof Brian Ripley wrote: >> What version of R and OS is this? Prior to R 2.7.0 there was little >> attempt to match output dimensions from various devices, and one of the png >> devices in 2.7.0 has an error in doing so, fixed in R-patched (see NEWS). >> >> On Mon, 12 May 2008, Michael Friendly wrote: >> >>> Hi >>> >>> In the following, the graph I see on the screen and the .png output >>> coincide. However, in the .pdf file, the fonts seem to be scaled >>> fairly larger, resulting in the label for the top legend disappearing. >>> Is this an infelicity or bug, or is there something I've missed? >>> >>> More generally, how do I control the size of fonts used in legends >>> and axis labels? >>> >>> library(car) >>> library(ggplot2) >>> >>> qp <-qplot (education , income , shape=type , size=women , colour=prestige >>> , >>> xlab="Education" , ylab="Income", data=Prestige) >>> + scale_y_continuous(limits=c(NA, 20000)) >> >> Hmm, you can't break the line before '+'. >> >>> qp + scale_size(to=c(1,8)) >>> >>> ggsave(file="prestige-ggplot.png", width=6, height=5) # OK >>> ggsave(file="prestige-ggplot.pdf", width=6, height=5) # fonts too large >> >> I would not expect you to be able to specify a smaller size without also >> reducing 'pointsize'. E.g. dev.print() does so, but ggsave seems not to. >> >>> -Michael -- Brian D. Ripley, ripley@... Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help@... 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: ggplot2: font size mismatch for pdf output> There is a bug in ggsave() for bitmap devices: it computes the width and
> height from 'dpi', but it fails to pass that information on to the devices, > which assume 72dpi. So what it actually asked for was a > 8 x 6.67 inch plot at 72dpi. 72dpi would be a better default, as not all > of the many bitmap devices work correctly at other resolutions (and none did > prior to R 2.7.0). Thanks for the bug report. I've fixed it by changing the default dpi to 72, and passing res = dpi to the raster devices. However, in light of the fact that most devices don't support dpi, I wonder if using units (like the raster devices) would be more appropriate. Is there any likelihood that the vector devices support will support the units argument in the future? (I also added support for the tiff device, and fixed a severe bug with postscript output) Hadley -- http://had.co.nz/ ______________________________________________ R-help@... 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. |
| Free Forum Powered by Nabble | Forum Help |