Multiple plot using layout grid

Hi,

I have a dataset similar to below example.
I would like to create a multiple chart in the layout grid format.

Can someone help me to create an R code for the same? Thanks in advance.

Example output (expected):

Data format:

|Year|Sex|Country|Score|
|2015-16|Boy|AAA|52|
|2015-16|Girl|AAA|51|
|2016-17|Boy|AAA|52|
|2016-17|Girl|AAA|50|
|2017-18|Boy|AAA|51|
|2017-18|Girl|AAA|49|
|2018-19|Boy|AAA|52|
|2018-19|Girl|AAA|49|
|2019-20|Boy|AAA|52|
|2019-20|Girl|AAA|49|
|2015-16|Boy|BBB|52|
|2015-16|Girl|BBB|51|
|2016-17|Boy|BBB|52|
|2016-17|Girl|BBB|50|
|2017-18|Boy|BBB|51|
|2017-18|Girl|BBB|49|
|2018-19|Boy|BBB|52|
|2018-19|Girl|BBB|49|
|2019-20|Boy|BBB|52|
|2019-20|Girl|BBB|49|
|2015-16|Boy|CCC|50|
|2015-16|Girl|CCC|49|
|2016-17|Boy|CCC|51|
|2016-17|Girl|CCC|49|
|2017-18|Boy|CCC|51|
|2017-18|Girl|CCC|48|
|2018-19|Boy|CCC|51|
|2018-19|Girl|CCC|48|
|2019-20|Boy|CCC|51|
|2019-20|Girl|CCC|49|
|2015-16|Boy|DDD|48|
|2015-16|Girl|DDD|47|
|2016-17|Boy|DDD|48|
|2016-17|Girl|DDD|48|
|2017-18|Boy|DDD|48|
|2017-18|Girl|DDD|47|
|2018-19|Boy|DDD|49|
|2018-19|Girl|DDD|46|
|2019-20|Boy|DDD|49|
|2019-20|Girl|DDD|49|

This example will get you started

library(ggplot2)

sample_df <- data.frame(
  stringsAsFactors = FALSE,
              Year = c("2015-16","2015-16","2016-17",
                       "2016-17","2017-18","2017-18","2018-19","2018-19",
                       "2019-20","2019-20","2015-16","2015-16","2016-17",
                       "2016-17","2017-18","2017-18","2018-19","2018-19",
                       "2019-20","2019-20","2015-16","2015-16","2016-17",
                       "2016-17","2017-18","2017-18","2018-19","2018-19",
                       "2019-20","2019-20","2015-16","2015-16","2016-17","2016-17",
                       "2017-18","2017-18","2018-19","2018-19","2019-20",
                       "2019-20"),
               Sex = c("Boy","Girl","Boy","Girl",
                       "Boy","Girl","Boy","Girl","Boy","Girl","Boy","Girl",
                       "Boy","Girl","Boy","Girl","Boy","Girl","Boy",
                       "Girl","Boy","Girl","Boy","Girl","Boy","Girl","Boy",
                       "Girl","Boy","Girl","Boy","Girl","Boy","Girl",
                       "Boy","Girl","Boy","Girl","Boy","Girl"),
           Country = c("AAA","AAA","AAA","AAA",
                       "AAA","AAA","AAA","AAA","AAA","AAA","BBB","BBB",
                       "BBB","BBB","BBB","BBB","BBB","BBB","BBB","BBB","CCC",
                       "CCC","CCC","CCC","CCC","CCC","CCC","CCC","CCC",
                       "CCC","DDD","DDD","DDD","DDD","DDD","DDD","DDD",
                       "DDD","DDD","DDD"),
             Score = c(52L,51L,52L,50L,51L,49L,
                       52L,49L,52L,49L,52L,51L,52L,50L,51L,49L,52L,49L,
                       52L,49L,50L,49L,51L,49L,51L,48L,51L,48L,51L,
                       49L,48L,47L,48L,48L,48L,47L,49L,46L,49L,49L)
)

ggplot(data = sample_df, aes(x = Year, y = Score, color = Sex, group = Sex)) +
    geom_line() + 
    facet_wrap(~Country)

Created on 2020-11-02 by the reprex package (v0.3.0.9001)

To learn more about how to make plots you can read this

Note: Next time please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This is exactly my expectation.
Thank you very much for your help and guide on Data Visualization.

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.