0

Although my question is related to line graph, it can be generalizable for other types of graphs and here it is.

Recently, I am trying to plot a facetted geom_line to show the annual change in particular groups given in my dataset. In other words, I do have more than 100 groups which I want to plot only 6 in a facetted graph with 6 different panels, one panel for each. However, pay attention that I do want to keep other groups in the plot, I do not want to remove them. I just want to highlight each particular group that I am interested in for each unique panel relevant to them and I want to customize the size in the panels for each groups so that they can be a bit thicker and therefore they can be seen more explicitly compared to others.

Therefore, my X axis is date (years), and my Y axis is Count. Here is the code I achieved that mission partially.

ggplot(df, aes(Year, Count, group = group, color = group)) +
  geom_line(alpha = 0.5, size = 0.1) +
  scale_color_manual(values = c("A" = "#DC8665", "B" = "#138086", 
                                "C" = "#534666",
                                "D" = "#CD7672", "E" = "#EEB462", "F" = "blue")) + 
  gghighlight(MİLLİYET %in% c("A", "B", "C",
                              "D", "E", "F"),
              use_direct_label = FALSE) +
  facet_wrap(~ group) +
  geom_point(data = d_filtered_point, aes(x =Year, y = Count, color = group), size = 0.3) +
  geom_text(aes(colour = group, label = group), vjust = -0.8, hjust = 1,
            data = d_filtered_point,
            size = 6) +
  theme_classic()

My code plots a facetted geom_line graph with 6 different panels, one for each group I am interested in by highlighting it while keeping other more than 100 groups and color them uniquely as shown in the below.

enter image description here

However, I also want to customize the size for these 6 groups as well to plot the particular group bolder for the particular panel, for instance make the particular group for the top left panel thicker. Although I searched a lot on the web, I could not find a solution. Therefore, I need your help, and I do appreciate your assistance in beforehand.

mzkrc
  • 219
  • 2
  • 7
  • 3
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data so that we can run your code and figure out a solution for your issue. – stefan Jan 20 '23 at 09:41
  • add a column "size_line" to your data frame df. In this column you can specify the line size you want for corresponding rows / individuals (ie: 1 for normals and 3 for the ones you'd like highlight). Then in geom line, you will be able to add aes(size=size_line). – Beeflight31 Jan 20 '23 at 10:37
  • Thank you for your comments and suggestions. I have tried to provide as detailed explanation as possible but sure, you were right that I should have provided at least a fake data. With regards to customizing '''size_line''' argument, it does not give me what I wanted at first place because it just makes bold every group I am interested in in each 6 panel. Yet, what I want to have is to make bold only the specific group I am interested in for the particular panel. Nevertheless, finally, I was able to find a solution. I just put '''linewidth = 0.5''' argument to geom_line and then add this – mzkrc Jan 20 '23 at 11:22
  • 'unhighlighted_params = list(linewidth = 0.1, colour = alpha("grey20", 0.1)' inside the 'gghighlight'. It gave me what I wanted. – mzkrc Jan 20 '23 at 11:23

0 Answers0