zorro
February 10, 2021, 10:08am
1
Hi
I have an R script which works well if the facet_wrap
's n_row
is small. However if I increase n_row
to a large number the plot area of each chart is reduced to a very small plot. Here is the script:
group_by(Session,Site,Risk) %>%
summarise(n=n()) %>% top_n(10)
plot1 <- ggplot(DF, aes(x = Session, y = n, color = Risk)) +
theme(axis.text.x = element_text(angle = 45), legend.position="bottom",
legend.text = element_text(size=7)) + geom_point() +
geom_line(aes(group = Risk), lty = 3) + guides(colour = guide_legend(nrow = 3)) +
facet_wrap(~ Site, nrow = 4)
ggplotly(plot1) %>% layout(legend = list(orientation = "h", x = 0.4, y = -0.2))
so for nrow=4, the charts look acceptable:
However if I increase nrow to 32 in order to see only one chart per line, it becomes like this:
So I was thinking to increase the the vertical size of the overall plot if that is the best approach.
How do I do it? Or is there a better way?
lars
February 10, 2021, 11:18am
2
Hi @zorro ,
As you didn't mention where the plot needs to be displayed I can point you to these resources:
See chapter Figure sizing of the R4DS book
This book will teach you how to do data science with R: You’ll learn how to get your data into R, get it into the most useful structure, transform it, visualise it and model it. In this book, you will find a practicum of skills for data science. Just...
See chapter Output for Presentation of the Graphics Cookbook
This cookbook contains more than 150 recipes to help scientists, engineers, programmers, and data analysts generate high-quality graphs quickly—without having to comb through all the details of R’s graphing systems. Each recipe tackles a specific...
If it concerns an R Markdown document, then section Options can be insightful:
If, however, you want to change the size in the Plots plane of your RStudio, then you can select Export > Copy to Clipboard..
where yo have the ability to resize your plot. You may find the checkbox Maintain aspect ratio
useful.
Hope this provides you some help in the right direction.
zorro
February 11, 2021, 6:35am
3
Thanks Lars, I am actually expecting to see it on the viewer itself however your suggestion solves my problem.
system
Closed
February 18, 2021, 6:35am
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.