Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Margin figures text size #19

Open
aridus opened this issue May 17, 2019 · 2 comments
Open

Margin figures text size #19

aridus opened this issue May 17, 2019 · 2 comments

Comments

@aridus
Copy link

aridus commented May 17, 2019

Using the code below the figure that appears in the margin has an overly small font size. Do you know if Is this something that is a result of the data/plot, or the way that msmbstyle is doing the formatting?

# If tidyverse package not installed in RStudio, remove '#' from next line 
# The read_csv comamnd is part of the Tidyverse package readr
# install.packages("tidyverse")
library(tidyverse)  

# Read the data
data <- read_csv("country,number_of_species
                 Ecuador,96
                 Peru,87
                 Colombia,52
                 Bolivia,43
                 Venezuela,18
                 Argentina,7")

# Default ggplot figure style
# Note that the package is called ggplot2 but the command is 'ggplot'
ggplot(data, aes(country, number_of_species)) + # Specify x first, then y
  geom_bar(stat = "identity") + # Plot type
  theme_gray()

With grateful thanks.

@grimbough
Copy link
Owner

msmbstyle doesn't really influence the plots directly, it just puts in the margin whatever has been created by the code + knitr/markdown.

If you want more readable fonts plots from ggplot2 I see two option:

  1. Use the chunk options fig.width, fig.height, dpi to modify the size of the image that is produced. The font size tends to remain static relative to the image resolution, so a high-resolution plot ends up having really small text. Conversely, choose smaller than default options (which is probably fine for a relatively small margin picture) and the text appears larger. This would get you a square image with 400px & 400px:
```{r block1a, fig.margin = TRUE, fig.width=2, fig.height=2, dpi=100}
  1. Use the theme elements in ggplot2 to increase the font size. For your example, the theme_grey() function has an option to set all fonts to a single value e.g.
ggplot(data, aes(country, number_of_species)) + # Specify x first, then y
  geom_bar(stat = "identity") + # Plot type
  theme_gray(base_size = 20) 

You can of course combine both of these to produce smaller images to speed up loading, and also adjust the font size in ggplot.

@aridus
Copy link
Author

aridus commented May 17, 2019

Ah, that inspired me, thank you. Using

fig.width = 2.5, fig.height = 2.5, dpi = 100, out.width = '100%',

works well, as the plot is scaled to the full width of the margin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants