I would like to change the default font for all plots in R to Times New Roman (without having to specify them per plot). Each plotting command in R has a different setup to change the font, which can make it quite exhausting. Is that possible?
Related
Just started R a couple weeks ago. Getting familiar with ggplot. I successfully made the graph I wanted to including all legends, axes titles, etc. I'm able to export/save this image fine. However, the assignment also required me to change the font used for the title, axes, legend text, etc. on the graph. To import the font I wanted to use, I used showtext as I saw this recommended when I Googled. When I use this, it does change the font to what I want. However, although I can see the entire graphs and its two legends fine in the Plot viewer, when I go to export it, the legend text is now cut off on the right. This appears to be the case as soon as I load the showtext package and use showtext_auto(), even if I just try to then recreate the graph using R's default font, not even with the new font. I've spent tons of time playing around and can't seem to resolve this. Please help. Also would be preferable if there is a more permanent way to get fonts into R rather than me having to load showtext and whatever font I want each and every time. Thank you very much.
I am using Julia notebook and making plots using basic Plots package.
A plot looks good, except its entire size.
I can change the plot size and font size of labels individually. But it becomes less readable unless I change the font size and line width for every component.
So is there a way to change the size of a plot as a whole? I also hope I can change it by default.
To answer your original question in the title, you can change the size of the Plot Window by specifying the size attribute as you already are in your code. See here: http://docs.juliaplots.org/latest/basics/ for more details.
As pointed out by Rashid, you can use the scalefontsize function to scale the font size. You can also scale the thickness by setting the thickness_scaling attribute, see here for more details: http://docs.juliaplots.org/latest/generated/attributes_plot/
To be clear, there is not currently a unified way to scale a plot in the way you are looking for it right now, it has to be done manually (though it would be great to have this unified scaling). I opened a feature request for this here: https://github.com/JuliaPlots/Plots.jl/issues/3153
I'm using the PDF device in R and I would like if possible to incorporate some characters from the zapf dingbats font in my legend lables (specifically the large open and filled circles for cloud situations of overcast and clear sky).
I found the extrafont package https://cran.r-project.org/web/packages/extrafont/extrafont.pdf but that seems to change the overall font. I also know how to use expression for greek and math symbols, but that doesn't seem to include these symbols.
I attach a plot that I made with NCL to show the kind of lable I am trying to recreate in my R script.
You just specify the appropriate Unicode value.
plot(iris[,3:4])
legend("topleft", legend=c("\U2600", "\U2601", "\U2602", "\U2603"))
I am trying to create a plot in R using ggplot2. The figure looks great when displayed in R, but when I write it to pdf the labels in the legend slightly overlap the different color lines they are defining. How do I add white space between entries so that this does not happen?
Without code example it is hard to say, but if you don't see this problem in the R display and you see it in the pdf, you can try to increase the pdf output size. When rendering a pdf, the font size is kept and the elements of the graph are more squeezed if the output size is smaller than the displayed one.
p<-ggplot(mpg,aes(cyl,year))+geom_point()
ggsave('yourfile.pdf',p,width=10,height=10) # default is 7 on my install
I don't know if it is possible to change the spacing, but I don't see any parameters for that in the theme() or element_text() documentation
I have a 2k lines script that generates several complex plots (plots in plots, custom plot functions etc).
I would like to change the default font to Times New Roman or Arial. Is it possible to do it globally or on a per session basis? I can't go through my script and change every plot() or text() etc. Thanks
You could change the settings at the beginning of your session using par(family="the-font-you-want"). If not overwritten afterwards this will affect all the plots in your session.
par(family="HersheyGothicEnglish")
plot(1:10, main="Stylish Font Family")
The number fonts that come along in R are quite limited though (see family parameter in ?par). You can extend the number of fonts you can apply (to use e.g. Arial) using the extrafont package.
Here you will find a good explanation of how to do that.