 Hey folks, in this episode of Code Club, we're going to take this figure and this figure. We're going to smash them together and we're going to produce this figure. How are we going to do it? Well, keep watching and I'll show you how. Hey folks, if you got to watch the last episode of Code Club, you know that I went through and did a pretty thorough critique of what I liked and what I didn't like about this figure published by Ipsos from last winter where they were looking at vaccine receptivity in 15 different countries using data that they collected in surveys from August as well as October of 2020. Of course, the data are dated, but it's still a kind of interesting visual to do a lot of work with and learn more about R. Fast forward, I received an email newsletter from a group called Chart R, no relation to R, where they took that same data and made this version of the figure. Actually, this is my version of their figure. And again, in the last episode, I went through and did a critique and kind of said, you know, this is what I like and don't like about each of these. Here's a figure that I would like to make. And I did a mock up in Keynote and so it's not a polished version of the figure, but it's a roadmap for where I want to go in today's episode. So I'm going to take the Chart R version of the figure and we're going to modify it to incorporate a number of different changes to make what I consider at least a more attractive version of the figure. That does a better job of telling a story about people's receptivity to receiving the COVID-19 vaccine. We're going to head over to our studio and get going. As always, I would absolutely love for you to follow along with me using your own computer and your own code to get started. Down below in the description is a link to a blog post for today's episode where you'll find code for two R scripts as well as the data that we are plotting. The two R scripts, one of them is the Ipsos version of the figure. The second is the Chart R version of the figure, which I've renamed to be August, October, 2020, makeover.r. That is going to be the foundation for our work today. I'm going to go ahead and run my entire R script to make sure it works and make sure it generates the file that I'm looking for without any error messages that ran through without any errors produces the TIF file of our version of the Chart R figure, which I think is a pretty good reproduction of the original figure. The first step that I want to take on is fixing the title, putting in a subtitle, and then bringing over the caption that we actually had for the Ipsos version to this. So the title here, Vaccine Skepticism by Country, attempts to tell a story, but it's kind of flat. The Ipsos version had some version of their legend title, right? So if a vaccine for COVID-19 were available, I would get it, was I believe the Ipsos title of their figure. If I look at the Ipsos website at their page where they published the figure that we started with here, right, the title of this blog post or this article, I think would be a great title for our figure. What do you think? I think it's provocative. It's bold. It's right there. It tells you what the figure shows. So I'm going to go ahead and copy this. I'm going to come down then into where I'm producing this figure down here in this big, long code block for building the plot. And I typically put the labs down here after my various scales. And here for my title, I'll plop that in there. And so that then puts the COVID-19 vaccination intent is decreasing globally. Great. I'm going to remove the chart R x-axis label. It was pretty cool to have it stylized to have two different colors, but it's not appropriate for what we're going to be remaking it as. So we're not going to have an x-axis label. We're not going to have a y-axis label. The caption here, ipsos, is a bit more abbreviated than what we saw in the ipsos version. So I'm going to come back to my ipsos code. And I'm going to grab that caption. Because as you can see, it has a bit more information in it. Copy that and then bring that and replace the caption. And I also then want to take the title that I had for the ipsos version and make that the subtitle of my makeover version. So I'll grab that. And again, I'll put that in here as the subtitle. So I'll say subtitle. So I'm also going to turn off the legend. We might revisit that here in a bit, but you'll recall that up here in show legend, we said true. So for now, I'm going to put that to false. And let's go ahead and re-render everything. All right, so we've got some funny stuff going on with margins, but we have all the text in there. So let's go ahead and into our theme and turn off the margin that we have on the main title. Also, I think there, if I recall, is a negative margin here for this, the caption that we had. So the first margin to change is the plot title. And so again, we had that margin here. I'll go ahead and remove this. And then also our caption, I believe had this margin. Yeah, where the top margin was minus 10. So we could pull it up and made it at the same level as the x-axis label. So obviously we got rid of those extra margin spaces between the title and the subtitle. We also no longer have the caption down here in the bottom left writing over our x-axis labels. We're going to get rid of those eventually, but again, let's just kind of work with the blank canvas here, if you will, kind of starting clean. The title I notice is running off the right side of the screen. I would like my title to actually be two lines and to use up the full width of the figure. So let's go ahead back to our labs function. And let's try to pick a point that's kind of in the middle where we can put a line break. So I think after intent, I'll go ahead and put that line break in there. And so that then gives us a fairly balanced title. We're not going to get a perfect full width two line title. I'm not a big fan of the font that they use. They use this Josephine slab, which is I think part of the chart are styling. They use that font and everything. What I would like to do is revisit the fonts that we're using by going back to Google Fonts. So I've plugged in the title into Google Fonts and I'm looking at all these different categories and looking at the different categories, I thought it would be cool to play around with, you know, maybe looking at a display font. So the display fonts are generally kind of, I don't want to say goofy, but different way of looking at the text. And for that title, I want it to be bold and to stand out. And so again, these are what they consider those display fonts. And so one of the fonts that I found that was really striking to me was this Patchua one. And so it again is bold. It's a little informal, but still formal. It's kind of a, it is a serif font. And I like that it is bold and that it really kind of pops out at me. So I want to use this Patchua one font. In the earlier episode where I talked about fonts, I talked about how we could use this show text package to bring in fonts to define our own families from Google fonts. So that's what we'll do here. So instead of Josephine slab, we're going to use Patchua one. And so then for the family, which we'll use down below in the theme, I'll do Patchua one. Let's make sure all this is loaded. And then we can come back down to our theme and looking at the plot title, I can put in replace of Josephine slab for the family. I can say Patchua one. And that gives I think a much bolder and really nice way of looking at that title. I noticed that the dots on the eyes are above the margins. We might need a little bit of margin space for the title. We can add that. I think we can also make the font a little bit bigger so that kind of the text from COVID to the T in intent goes all the way across the width of our figure. Again, we can come back up to our plot.title and let's maybe bump this up a little bit to say 28. And so that does a much better job of filling the horizontal space. I'll go ahead and add a small margin to the top of my plot title. And again, we can do margin equals margin and I'll do T equals, let's do 10. And so that gives us a little bit of breathing room at the top of the figure. So for the rest of the text in the figure, we were using Josephine sands, which is kind of the sand Serif compliment to the Josephine slab, which was a Serif font. If we come back to Google fonts, one of the nice things that they have are popular pairings that people have used to go with patch one. So in this example paragraph, the title here is in patch one and the rest of the text, you can change to be any of these different font options. So Roboto, Roboto is the most popularly used font on Google fonts. If you look at the riffamonus.org website, the main body text is all in Roboto. There's also open sands, Lato, we get rid of the highlighting there. Railway and Montserrat. The Montserrat seems a little bit more open and airy than like the Roboto does. I think I'm gonna go with Roboto much like we did with implementing patch one. We can come up here and we can say Roboto and then the family, I'll do Roboto and I'll grab that family name and we will come back down. There's a couple of places that we need to update the font family. The first is in text where we will then say Roboto and then up above, I believe we had ggtext right here where we also use Josephine Sands and I'll say Roboto there and I'll do a search on Josephine and I had a x-axis title here being element markdown but we got rid of the x-axis title completely so I'll go ahead and delete that line because we don't need that in our theme anymore and then I think that got rid of, yeah, all of our occurrences of the Josephine slab or Josephine Sands. So this gives us the Roboto font for our subtitle, our y-axis labels, all the numbers next to our points as well as for our caption here and also these x-axis numerical values. I'm pretty happy with the way this looks. One little thing I'm going to tweak is maybe go ahead and put a little bit of a margin below the title because it does seem that the subtitle and the title are running into each other especially with that g and the l in the globally and available here. So again, we'll come back up to plot title and for the bottom, let's do five and then again, that gives us a little bit more breathing room between the title and the subtitle. The next thing that I want to turn my attention to is getting rid of these values on the x-axis. As we talked about in the last episode, I think it's a little bit busy to have numbers right next to the points like we do here. So like this 88 and 79 for Australia as well as having the numbers at the bottom. If we removed the values next to the points then we are asking our audience to kind of scan up and down the figure, which is a lot of work, right? So in a way, it is nice to have the number next to the point. Maybe something we could think about doing is making that number actually a little bit smaller. So it's not such a pronounced part of the figure. So I want to get rid of these numbers on the x-axis. I also want to get rid of these tick marks on the y-axis because they don't think they really add anything when we've got this alternating colored background in the main body of the panel, which I like. But again, soon, soon we're going to change those colors to be a little bit more subdued. I will come back up here and looking at my scale x continuous. I still want my limits to go from 50 to 100 but I no longer want the breaks and I no longer want the labels. So to get rid of the breaks and the labels, so if we don't set anything, if we remove those two lines, it'll put in default values, labels and breaks. So to get rid of those, we can put in null. So that cleaned up the presentation a bit by getting rid of those numbers on the x-axis. Let me know what you think about getting rid of those values on the x-axis. As a scientist, I feel weird, kind of removing that very traditional part of every figure. But again, we have those numbers right there next to the point. So I don't think it really adds anything. Let's go ahead now and remove our lines for the x-axis, the y-axis, as well as those tick marks. Again, coming into our theme function, we can look at axis line and remove that. So now we see those gray axis lines are gone. Now we want to get rid of those tick marks. Those tick marks on the y-axis were created in part by this line here in the theme function. I'll go ahead and comment that out for right now, as well as up here on the scale y continuous. And so we want the scale y continuous as a way to place the country names, but we don't need it for placing the tick marks. So we need to modify the scale y continuous. And to do that, what we really need for the breaks are data y position. So we can get rid of everything else here. And then for the labels, we need data dollar sign country and we can get rid of everything else that's there. All that other stuff was in there for those tick marks. So that gives us a tick mark now for our individual countries. And so it wasn't enough to just comment out axis ticks y. We actually want to also set that to element blank like we did for axis ticks x. And you know what? I think we can make axis ticks without an x or y and setting that to element blank should make all of our tick marks on the x-axis and y-axis blank. So that did get rid of those tick marks along the y-axis. And I think, again, removing those things from the axes is really cleaning up the presentation and making it a more attractive visual. The next thing I wanna take on are these alternating colored backgrounds. I like the alternating colors, but I'm not such a fan of color. I'd rather this be more subdued and traditional and really let the color be the points. What I want for the alternating color is to have a light gray as well as a white. Now, in this figure, you'll notice there's a space up here at the top between India and my subtitle. That's because there's actually a row here for what they called total. Total was really an average across all of these 15 countries for the two dates. So that's still in there and this was actually a third color. And so when you look at our scale fill manual, you'll see that we have three break values, A, B and C. The data frame that's generating that is the stripped data and that no longer had the total because we got rid of the total. So we don't really need the C anyway. So we'll go ahead and reduce the number of breaks down to two and the number of values down to two. And we'll go ahead and get rid of those labels, which didn't matter anyway. And so I need two values. I need white and I need a gray. And so my white, I'm gonna make FF, FF, FF. So again, the two characters go together. So it's red, green, blue. And so all F's is white. And then for gray, again, we've got that red, green, blue. That if the value in red, green, and blue is the same across all of those, we'll get a gray color. So I'm gonna go ahead and do F8 in all three channels to get a gray color. If it's too dark or too light, we can go ahead and adjust from there. So I think that gives a nice alternating colored background. Of course, we want the background of our plot to also be white. So we can come back up to our plot background and we're filling that. And again, we can put in white. We can also name white in quotes and get the same effect, but let's use the hexadecimal. That again gives us our white background. I think I'm gonna go ahead and make our title black instead of this teal color. Again, like we saw earlier, our plot title is gonna be 000000. So all zeros then in hexadecimal is black. The default color is black. So I could also remove color equals whatever, but let's leave that in there in case we want kind of a foothold to know where to change the color of the title should we change our mind later on. So again, that gives us a nice bold black title, nice clean background. And I really like this appearance of having these white and gray strips. Now, one thing I'm not such a fan of is that France is white and India is white. I'd rather have the plot be bookended, if you will, by gray. So let's go back into our scale fill manual and we can flip these values so that we have A being gray and B being white. So we see that we do now get those alternating colored backgrounds with France being gray and India at the top being gray as well. I just like having that kind of gray boundary on the plotting window. So it's not like those points are just kind of floating off into nothingness. I don't know, it's a small touch. And the other thing I wanna point out is that the A and B in our strip data frame are just kind of dummy values. They don't mean anything. They don't represent anything. They're solely there so that we can then use that scale fill manual to attach a color to those different ribbons in our figure. The next thing I wanna take on is altering the color of the points that we have in the figure. As you can see in the chart R version, there's this green point that is for the October point and the darker blackish color is for August. There was a legend here that again, we removed earlier. The Ipsos version had two different shades that were kind of related to each other, but there wasn't a really strong contrast to them. And you might recall that I had this challenge of constantly looking back to the legend to remember which color was August and which color was October. And so I would like to clarify that for our audience even better in this makeover version. So what I'd like to do is pick a really bold color for the October data. So perhaps like a really royal blue, a really strong blue color and then a paler shade of that blue for the August data. And so we can do that by taking the really strong blue and removing the saturation to again kind of make it more pale. And that way we've got two shades of blue. The brighter will kind of hopefully key to our audience that that's more recent. And the paler will key to our audience that's older. Of course, we will have a legend that we will be putting back in here as our final step in making over this figure. But the other thing that that will help us to do by removing the saturation is to give a stronger contrast than what we saw in the Ipsos version and perhaps a more meaningful contrast than what we see here in this chart, our version. Here in keynote, I have two white rectangles created. You could do the same exercise in PowerPoint or wherever. I just had keynote accessible to me. And so I've got this white rectangle on your right, my left, and I will pick the color wheel for the fill and I'm gonna pick a color that's right about here in this really strong blue color. Again, we could get the hexadecimal by going up to RGB sliders. So I'm gonna grab this and then plop that color, that same shade of blue onto the other side, the other rectangle, and I'm then gonna go to the HSB sliders. So HSB stands for hue, which is what we think of typically as the color, the saturation, which is kind of the blueness of that color, and then the brightness. So again, what I wanna do on this right side is take the same blue and I wanna pull down the saturation, right? So you can hopefully see that as we pull that down, we get a lighter color. Of course, we don't want it to be so desaturated that it's a white. So let's pick something that's maybe about a third of the way across and so we'll get this light blue color. Of course, we can get the red, green, blue for that and so that's gonna be this value down here. Coming back to our studio then, I will go up to my scale color manual and for my August, I want that desaturated value and then I will get the hex value for my stronger blue and put that in for my October value. So this gives us that really royal blue color for October data. I think it really does signify recency, current. Maybe it does, I don't know. Let me know what you think down below and then that paler blue being the older data and again, we do have a pretty strong contrast, but that pale isn't so desaturated that it blends in with the background and I think it looks pretty good and we don't see something that we saw in an earlier episode where my perception of this light blue or the dark blue is being altered by the gray or white color in the background. So there's a few things I wanna do to clean this up further. I'm gonna go ahead and remove our beloved arrows. At this point, I think it's just extra and just makes the plot more busy. We can come back up here where we actually had a data frame for arrows data and go ahead and delete that and then we also had geom path where we were plotting those arrows. So we modified that way back up here in our data pipeline and you'll recall that we said percent August, less than percent October, move it to the left if it's greater, move it to the right. If they're the same, so true, then we wanted to make it in a real. So I'm gonna go ahead and remove this true value as well as this true value. So then I'm gonna make these first case when lines to be less than or equal to. I'd now like to modify that text to be a bit smaller and we can do that way back up here where we had our GG text. We had size equals three. I'm gonna drop that down to size equals two. That does make it smaller. It's a bit far from the actual point. So I'm gonna modify the bump that we had way up here in data to maybe make it plus or minus two on each of these rather than 2.5. Now we've got those numbers closer to the points and it looks pretty attractive. I like the size and the proportion of them pretty well. I think that gray color also kind of keeps the number a little bit subdued so it's not overwhelming all the other stuff on the figure. Something that I think is kind of overwhelming the data in the figure are the handles of the barbell being this black line. I'd like to kind of soften that a bit and maybe give that the same gray as we see for the number and maybe make it just a smidge wider so that it's not lost kind of in the background. So to change the appearance of the handle on that barbell, I'll come back up to GM line and this color had been the color of the August data in the chart R version which is kind of that dark color. So I'm gonna go ahead and make it eights all the way across to give kind of a medium intensity gray and I'll make the size one make it just a smidge wider. And so now we see the handle on the barbell. It's not as pronounced as it was with just jet black. It's clear that the points are connected but it doesn't overwhelm and I think that kind of shifting that black to this gray really draws the eye to the dark blue points which is really where I want my audience to be paying attention. So the final step in this makeover is to implement a legend. We had taken off the original chart R version of the legend because my goal in this makeover was to insert vertical lines showing where the average response was across the 15 countries, colored by the two dates. So we'd have October with a vertical line and August with a vertical line. The more I've thought about this though since I made that episode, I'm thinking that's kind of stupid. I think that whole line, that row total or average was kind of stupid because if you think about it, it's the average of these percentages across the 15 countries. It doesn't make sense to do an average like that when there's so many more people in India and China than there are in the United States and France or Canada, you know? And so it's a weird way to do an average and I just, I don't think it's necessary. What I'd rather do than this is revert back to the chart R version of the legend and perhaps use this subtitle, which is similar to the title of the legend in the chart R version. I'll show you where there's a small difference, but it's an important difference. So we'll come back into our R script and I will comment out the subtitle for now and then we'll come back up to G on point where we have show legend equals false and turn that back to true. And so, yeah, I know it looks bad. And so we see a couple of problems. So the text of the title is overlapping with the legend. The colors of the text matched the color that was previous there for the point. So there's a few things to fix. Let's start by adding a margin to the bottom of our title so there's more space to see what's going on in the legend. So let's go back up to plot title and at the bottom margin, I'm gonna go ahead and make this 20 so there's enough room between that title and the legend. Let's now turn to the color of the text next to the point. This was inserted using a span, an HTML span with some styling using that element text from ggtext. I'm a bit worried that this August 20 is gonna get kind of washed out with the faint blue. We'll see, it's easy enough to change and then to convert back. Again, we can come up here to our scale color manual and our October is this hexadecimal, plop that in there and the August likewise. And so now we've got those two dates. You know, I do just feel like that August 20 is getting too light and hard to see. So let's go ahead and revert that back to black so we can come back up here and remove these two spans in the labels. It was a nice try, but yeah, it just, it doesn't look right. I don't know, maybe you think it looks okay. I don't know, not me. I wanna go ahead and look at the title. I wanna go ahead and grab this subtitle that we'd commented out and let's compare them. The differences are pretty subtle, but I think important. So we'll go ahead and put in this backslash N and what you'll hopefully notice is that the chart R version here on the bottom says, I would totally, I totally agree I would get it. So totally used in this context in American English at least is kind of what we kind of jokingly call valley girl speech. If you've ever seen the movie Clueless, which I know I'm dating me was a big movie when I was in high school. They would say totally as a way to say like they completely agree, right? Like that is just the way it should be, which is very different than actually the way the survey was asked. So totally I think in this context is taking that total and inserting it into the legend. And so what this really represents is a composite of people that have varying levels of agreement with the statement. So I'm gonna remove that totally and we'll use that as our legend and I'll strike this subtitle and I'll also go ahead and remove the subtitle from down here. So by shortening that title of the legend, those points came over closer to the right side of the title. I wanna insert a little bit of space there. Also, you might notice on the left side of the title, the left side of the legend, there's a scape space there as well. So we can change that with two steps. We can do legend dot margin, margin, and I'll say L equals zero. That will move the legend all the way over to the left side of the plot. Now we wanna add a right hand margin to the legend title and we can then do margin equals margin. And then R, let's do 15, that moves it. Let's bump that up a little bit more. Let's try 25 and that looks pretty good. So now looking at this legend for the last couple of moments, I'm realizing that we have October and then August. Let's go ahead and flip the order of those two months. To do that, of course, we can come right back up to scale color manual and we have October and August and I'm just gonna quickly flip the order of these two for the breaks and the values and the labels. And that sure enough, flip the order of our two months. So I think this looks really attractive. It definitely tells a story. Again, we didn't really change that much about the chart R version of the figure and we didn't really change that much about the Ipsos version of the figure. It's a few subtle little steps to try to use the data to tell a more compelling story than if a vaccine for COVID-19 were available, I agree I would get it, right? We put in a title that is bold, that is eye catching and tells a story, right? Intent is decreasing globally. And then we are using color by changing the saturation to show the elapse of time, which I think is again, really attractive. And we have that handled to the barbell there to show to the audience that the points are connected. And I think again, we've done a really nice job of making the figure more attractive. What do you think? Let me know down below in the comments. One thing that stands out to me though about this figure that I don't quite like and that I would like to experiment with is to instead of putting the percent on the x-axis to percent on the y-axis and then to put time on the x-axis, then we could have a line for each country indicating the change in over time of people's attitudes towards receiving the vaccine. It would become much clearer if all the lines are going downwards or I guess to your perspective downwards that there's this downward trend in vaccine acceptance. That is called a slope plot. And so that's what we're gonna talk about in the next episode. If you wanna watch that episode, please be sure that you're subscribed to the channel and you've clicked the bell notification so that you're sure to hear from YouTube when I post the next video. I'd love to share that with you as I've been kind of working through this project. I've had this in the back of my head that I really would like to see this data as a slope chart. I don't think it's gonna be a panacea for all problems. Again, no chart is perfect, but I think it will be an improvement upon this visualization. We'll find out in the next episode. Anyway, keep practicing with these types of tweaks, implementing ways of cleaning up the presentation of your figure, as well as trying to tell a story with your data. We'll see you next time for another episode of Code Club.