
{gt} Table Battles || Crosswords || RStudio
00:00 Introduction 00:34 Rich's gt table, with a focus on creating audio within a table 07:28 Jesse's gt table, with a focus on sentiment analysis Learn more about the gt package here: https://gt.rstudio.com/ Got questions? The RStudio Community site is a great place to get assistance: https://community.rstudio.com/ Content: Rich Iannone (@riannone) & Jesse Mostipak (@kierisi) Motion Design & editing: Jesse Mostipak Music: Nu Fornacis by Blue Dot Sessions https://app.sessions.blue/browse/track/98983
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
What did you think of the data set? Yeah, very wordy. I was like, what am I gonna do with this? I mean, like, I thought of something it's totally like, not too much analysis. It's kind of like, there's some interesting words here. Let's just feature some words. Yeah, I mean, like, I approached this, like, let's just like get a bunch of words and show me some long words and some short words and give me some definitions.
It was really fun because like, I was able to like find a package. Wait, what? A different package that defines words. It's called Dictionary with a capital R somewhere. Dictionary Define. I was like, that's kind of sweet. And you know what they do? They actually have like, they use an API, like they hit an API somewhere. And they're able to get like audio as well, like audio links. So I thought, let's put some audio in this table. This table can speak to you. I mean, tables always speak to me, but this one can actually speak to you.
This table can speak to you. I mean, tables always speak to me, but this one can actually speak to you.
Okay, so what I want to do is get like the types of words. And these are like long intro words, basically. I'm sometimes impressed with very long words. Like, well, yeah, about 15 letters. Yeah. And there's some words like, I don't know how to pronounce, like, I would like to see them pronounced. So this is actually quite nice. So what I'm doing here is like this, this will show me like random words. It'll just pick from like those, you know, giant word lists from those crossword puzzles. Okay. And give me like five long words, give me five short words, define them. It's almost like word of the day times five.
Building the gt table with audio
So it's good. So what I did was like, okay, so I got the, you know, as I did before in the last table battle, I just sourced like all the reading of like, you know, the tables. I basically just ignored all the columns except, this is so bad for Titus, they like ignore everything except one column. And basically I just got like all the words. And then I did some cleanup as I often do, you know, made everything more case, made it all nice, sorted the long words from the short words. And then I hit this API, which was, you know, given to you by this dictionary.
Is it, I just searched for like, you know, a grant package that would be like, you know, offer me some definitions. And this is like a three star package that deserves more than three stars. So if you see dictionary around, give it more stars. Like it does a lot. This is some work here. So I had to do a heck of a lot of stuff because like, sometimes it would just be like weird outputs. So I had to like do some pretty wild stuff to make it like work like all this stuff.
So ignore this, this is just basically just trying to like fish out like one, like a pronunciation, like phonetic pronunciation. I love like possibly like a list, which may be empty. So I had to go through all this. And then finally I get the audio link. And here's a cool thing. So I finally get to my gt table. Okay. Another thing I noticed the API hits doesn't always give you like a lot, sometimes words defined. So basically what I do is I get 40 words and then I score them in terms of like what it offers in terms of metadata, like that's all this stuff. And then I sort them and just get the cream of the crop as it were, you know, like I basically descend by the score, slice the head. And then I get like, you know, words with, you know, some stuff to them.
I did the same thing as last time. I made columns with, I defined the widths. Here's a really cool thing. You can like in most browsers, well, all browsers circa a long time, you could now like use an audio tag and you can provide the URL, which is what dictionary that R package does. And you just wrap like the URL inside these tags. And then you get like, you know, it's playable. You get like this little like audio player in your freaking table. So I'm going to show you this. And like, there's some cases where you don't have audio. So I can do this basically to make it work.
Eventually it gets to the end. I'm going to show you this table or this function really show me words I can choose from times or so here we go with times. It takes like a few seconds because it's doing some query. Okay. Some API stuff. Okay. Here we go. Here's a selection of words, both long and short. And yeah. So it's sorted by long words, short words, and here, check it out right here. This is where you get audio. See, sometimes you don't get the audio. Yeah. Sometimes you just, just bad luck. Okay. Hopefully this works. Well, here's, here's some beans. You heard that? You heard that? Okay. Awesome.
Steal. Yeah, I know these words. I'm going to do this again. This is like rolling the dice one more time. Maybe a big day will provide. We got some, we got some hits. Disproportion. Here we go. Disproportion. Nice. Well read. Degeneration. Same person. Same person this time. Proportionate. Yeah. Oh, we've got a long word aficionado. Oh, did you know that Drake is a male duck? Drake? I don't know that I knew that. What is fichu? Fichu? Fichu. Oh, wow. It's a scarf. Now I know. Okay. Patrol. How they pronounce patrol? Patrol. Patrol. Yeah. I mean, like that's got some Britishisms going on.
But yeah, like this is, this is the final word. It's amazing. Yeah, this is what I did. This is my like, my little twist. But this could be a shiny app. Yeah, it could be in a shiny app. I think for word a day. Oh, yeah, of course. Yeah, because it's function. And it just produces a table. It's got like a height, which I think I control because what I did is I also set the height. Not so easy to do in a table if you have like overflow. So you have to sort of set that a bit beyond what you expect.
Okay, there's probably a way to really fix it with overflow stuff. But I always can't figure it out. And like 10 stack overflow searches later, I just give up. But I did this line height, and then max height, and height. And then maybe this does something. This overflow, like, I use it sometimes. And I think it fixes the problem. But I'm not confident. Yeah, yeah, you really get experiment, like in the sort of like the dev tools. So add a bunch of CSS.
And again, I'll just repeat this one more time. If you do that, it's really vitally important that you set the ID on the table. Okay, right here in gt. And then once you do that, the reason why you do that is because we'll say you have like a, you know, some document with a bunch of tables on it, you just want to set the typically just want to set like the CSS for the one table you're focusing on, and not for every other table. So it just protects against like, you know, multiple tables. So if you didn't have this, it would just be like, maybe that's good. Maybe that's bad. But I just figured it's bad.
Jesse's sentiment analysis table
Yeah, so these are my functions. So just proving that you can make tables from functions, and it's not that bad. So like you, I was very much, we're not getting tables with, with data, or number, there's data, but we're getting so far, we've hit anys, and then text data. Yes. So what I thought I would do is play around a little bit with tidy text from Julia Silky and Dave Robinson. Excellent idea. So like, get sentiment for these words, right? That's exactly what I did. So I was like, well, what's a good way to group things that's not too large? Like, I don't want like this massive table. So I was like, okay, do I want to do the clue or the answer? And I went with the answer, because I didn't want to like strip out all of the numbers.
And then also does the answer if you're using the clue, I was like, I don't know that that gives you a sentiment, because the clues are often placed on words. Yeah, yeah, knows that, that they're really like, like, I don't know if I can ever get into these puzzles. I mean, I know a lot of people that do. But like, wow, it takes, it takes a while to get into it. These are tough. Yeah, some of these are hard.
So I was like, you know, I played around with it a little, got to use a little luber date, which is always fun. So converting the numeric, I just wanted the month. And then I essentially went through, I did have some NA dates. So I just dropped those. I'm definitely a just get rid of the any values defaults. Sorry to everyone out there who does not believe in that. Um, and then I what did I do? Yeah, so I did that. And then I kind of played around with things. And I just used so Julia and Dave recommend three libraries. And this is from tidy text. So I just went with one of them. And I did a little join. And got a nice little Actually, let's run some of this.
Yeah, let's see what we get. Running a whole bunch of stuff we don't need to run. And that's fine. So big, I didn't know what big Dave was, but I read it in. And then I just I just worked with the times data, you could do all of them if you wanted. But basically, I got the month, the word, the sentiment, and then the count, like the number of times that it appeared. So I was like, Oh, okay, what I could do is I can group by month, and then this combines all the years. And then it was like, I could take kind of the number one negative word and the number one positive word for each time, see if times get seasonal affective disorder, or something like that.
Which are months there are things like negative in January. So I ended up using I was thinking about how I wanted to do this, I arranged it, and then I just did a slice max. And then, oh, yeah, here's like the basic table. So you've got your month, your word, and then your sentiment. And so I thought that was kind of fun. And then let's make it look a little nicer. So I went for a black and white theme, like as nice.
This is a Libra basketball. Yeah, I was thinking using basketball too. It seems like such a great like writerly font. Like, yeah, so the New York Times, it turns out uses Georgia and Georgia is not on Google fonts. I think I have Georgia, but I was like, we'll do Google fonts. So it's replicable for anybody at home doing this. Yeah, basketball is a cult classic. I'm glad there's a free version of that.
Yeah, so did that. I'm pretty happy with it. I couldn't get like, it bothers me that this space is bigger than this space. And so I spent some time like moving things around and just couldn't get it where I wanted it. It's tough, because like, it doesn't center nicely, then like everything gets crowded, it gets too thin. I don't know. It's, yeah, it was rough. You know, made it work.
I thought it was interesting. Like, you know, how did I, what's the best way to present things? Because there were a lot of ties, right? So February has multiple ties for its, you know, most positive words. And then, you know, like, I think there's something here around like the spread. So almost always you see your negative word, there's always like a clear negative winner. And then like a spread of positive winners. There's never really, like June, abolish an elite. There we go. Done deal. But there's, oh, okay, August, you see a lot more negative. I don't know what's happening in August. People are not as happy in August, I guess.
Yeah, like that. That's an angry month. Right? That's what I'm saying. Lots of anger. You're the idol, you're irate. You're going to sack something. Loose. You know, September starts to balance out October, you know, a little more negative than positive. But so I thought this was, you know, and then I've got like my little source notes in here. Oh, nice.
Yeah, I did not use fantastic. Glowing, lowering the line. I thought of it later. And I was like, it's okay. If I were to redo this, or if I were to like keep working on this, I was really curious about doing something where instead of just looking at the top, it kind of did a full sum of all the negatives, and then a full sum of all the positives, and then it gave you like a positivity proportion. So if it was let's take like blue and orange, if it's more positive, it's more blue. And like it would somehow color. That'd be interesting. Like the months themselves. Yeah. Yeah. So you could look at like January and be like, oh, that's really orange. It's a really angry month. Whereas February is blue. And you could like see how that swings. So that to me was like, that would be a really interesting programmatic next step.
Whereas February is blue. And you could like see how that swings. So that to me was like, that would be a really interesting programmatic next step.
And then maybe get a sample of like the most negative words. I'm surprised there's no neutral. I guess that's just the way. So it's the sentiment library. Oh, I see. So it doesn't have that, I guess, right? Yeah. So this sentiment library, you know, and like tidy text. My name is R. It's a great book. It goes into like all of the things that you need to think about when you do this kind of work. But it is just, I think that it is just positive or negative. Like that's it. It's a very dichotomous.
Yeah, that's right. Speaking of table design, I love what you did with doing away with the column labels. Totally not needed. It's obvious what's going on here. And you just used like the the group labels to like organize everything. Yeah, so I did that. That was, let me go in here. I just dropped them by putting them in as blanks. Oh, that's good because at least space, which is nice. Yeah, so you get a little space here. And then I thought about like, oh, like decorative borders. And I was like, no, it's almost like a newspaper column. Yeah, that's what I'm seeing here. That's the vibe I get totally.

