Resources

Rich Iannone || {gt} Intendo Game Data Project Walkthrough || RStudio

00:00 Introduction 00:11 Setting up our environment 01:21 Importing data 01:56 Data preparation using the tidyverse 14:12 Basic gt table 16:25 Specifying row order with row_group_order() 17:20 Formatting currency with fmt_currency() 18:10 Formatting missing values with fmt_missing() 18:55 Creating row groups with tab_options() 19:50 Relabel column names with cols_label() 20:41 Creating tab spanners with tab_spanner() 23:00 Creating a table title and subtitle with tab_header() 24:40 Aligning table title and subtitle with opt_align_table_header() 25:16 Creating a stubhead label with tab_stubhead() 26:00 Format all table cell text using tab_style() 27:25 Automatically format data color based on value using data_color() 30:45 Creating Markdown-friendly source notes using tab_source_note() 32:45 Creating Markdown-friendly footnotes using tab_footnote() 39:28 Adjust table column width using cols_width() 40:55 Adjust cell padding using opt_horizontal_padding() and opt_vertical_padding() 42:22 Change row group headers using tab_style() 43:40 Convert all table text to small caps using opt_all_caps() 43:58 Change all table text font using opt_table_font() 44:28 Changing table, table heading, footnotes, and source notes background color using tab_options() 46:41 Add a table "cap" at the top and bottom using table.border.top.width() and table.border.bottom.width() 47:23 Use multiline formatting with footnotes using footnotes.multiline() 47:34 Change line style using table_body.hlines.style() 47:55 Change table title and subtitle font sizes using heading.title.font.size() and heading.subtitle.font.size() 48:11 Checking out our final table! Code to recreate the table from the video: https://github.com/kierisi/rstudio_videos/blob/main/gt/rich-intendo-project-walkthrough/intendo-30032022.R 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) Motion design and editing: Jesse Mostipak (@kierisi) 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.

gt i'm super excited about this because i have so much good stuff

okay so i got this new thing so i call this file nintendo rev it's basically revenue from a fake game company called nintendo um you've never heard of it because it doesn't exist okay so library gt we need that it's got to have it and then we're going to do library nintendo it's a hard package to get it's on github if you just search it up you will find it and the cool thing about it is it has data sets of different sizes and we use all those data sets for this it'll be so nice uh and i like to library in tidyverse because we're going to use all sorts of tidyverse before making the actual table um the data table and then we're going to get in looper day because we're going to do some date and time stuff and i'm never sure whether that's included in tidyverse i think it isn't

okay great um so i'm gonna get all the revenue just by you know assigning it to this and okay so nintendo has a bunch of like data sets um like all revenue all sessions uh i'm gonna get the revenue uh so i'm gonna do that right here uh the default options are good this is like the size of the data set we'll just go for a small because we don't want to like you know tax the system too much so we're gonna get the data doing some stuff here but it just downloads the data from the repo and now we can totally see it i'm gonna make the console just a bit bigger because we'll do some console stuff initially so lots of rows of data like nearly two thousand two hundred thousand whoa okay it's a lot of revenue this company's doing well which is great uh good for nintendo

Exploring and preparing the data

um but it has lots of countries in it um and we're going to filter down this data quite a bit we're going to actually make something super narrow so in the end we definitely don't want more than like 50 rows i think to fit a table on the screen so we're going to make we're going to heavily summarize this so first thing we're going to do is make a vector uh for subsetting the countries

so i'll just say countries to consider so i'll call it countries and then i'm just gonna make a vector of the countries i know using like the two letter codes so i'm just i think it's us great britain uh we'll put in d e c h we'll make it a top eight uh norway canada then we'll do india and spain which is es so that's eight right yeah that's totally perfect

so now we have this this is some sort of prep work we need to do so we have that now we need to get um well first of all we have all these times for the revenue we want to break it down to like just like each month we're going to summarize for each month what the revenue was for each type of revenue uh just go over this table a bit so i'll tell you exactly what this what this all is so each player in the game has an id each time they play the game they have a session and that has an id as well there's a session start and the time of the revenue event so each row is a revenue event like a purchase of something and they can buy uh either an ip which is an in-app purchase usually some sort of like currency or a secondary currency or some game item or some special offer that's a combination of things and then there's revenue associated with that you know with that bought item and actually there's two different types there's also like uh item name might be like um ip or ads so ad views will also result in some revenue as well

okay and then there's a session duration so just amount of time they were in that session it's good analytics to have see how long they're playing and what triggered the sale uh a start date this is like historical data it's a start date for that player so we can get the player age from that uh so it's kind of like a redundant thing but it's good to have because you can sort of segment all this data by the player age and then we have other things to do with the player like their acquisition uh basically where they're acquired from like what ad caused them to play the game or convert into the game so it could be like other networks like facebook or ads on different platforms that got them into the game usually they represent with a link and then they're uh they install the app that way the game and then the country they're from which is basically uh some course location data which is just provided by max mind

okay so we have all that so now we really wanted to just break this down into like country uh month uh item type and then the total revenue and we're going to make a table from that it's going to be really pretty sweet okay so now we got the countries considered we explained the data a little bit there

uh so now we want to get the month names because in the end we'll just have like one two three total 12 as the column names uh but we want to make them you know like friendly sort of like nice month names so we'll do that um i just found this out today actually uh there's like a month name vector in r which is kind of cool uh but we just need the first three letters so we'll do like substring um from one to three and we'll see that it gives us just this and then later on we need this as a list to change the column names in gt which is a little bit inconvenient but that might change later but we'll just make it a list like this

okay great so now we'll just get this i don't really like lists because they're kind of like annoying but uh we have no choice so we have to make this list so we'll call this month names so and another sort of weird thing about gt is it needs a named list it's because it has to map the column name with the new label so these will act as labels but we need the name of each item in the list as like the actual column name that's not too bad because we know they're going to be one one to twelve so let's just do names month names uh so many names uh as character uh one to twelve okay so now if we do this and we take a look at month names we finally have this preparation step right here this would be good for later

Building the data pipeline

okay so now all the revenue okay we're gonna start there we're gonna build up this table like one line at a time maybe bunches of lines at a time but we'll see it every step of the way so right now we don't even have it in gt we just we still have this um and we still have to do lots of stuff before we get the gt uh for instance we need to do that month thing so we'll do mutate month is going to equal the date and then we want to use the month function and we want to use it on the time column right there that's the time of the revenue event okay i'm going to run this uh you won't see it because it's actually at the end but trust me it's just like the month as a number okay continue

filter we're going to filter a lot because we don't need a ton of stuff in this table uh because we want to focus a bit there's lots of data in this table but we want to just focus on a few things otherwise it gets too multi-dimensional so we'll say item type is going to be just the ip type and again it's in that purchase people things people buy and not ads people watch okay so that brings down the table down to 47 000 rows which is a lot better than before

um one thing we don't see here and this is something new from the data is the country is like a long country name it's not a country code which is fine but it's kind of big and so kind of hard to work with a weird thing about gt is it actually has this country pops data set which has great data but the cool thing is it has a bunch of country names and the country codes and they just happen to map perfectly with this data set so we can actually like do a join and get the country codes from this uh you get the two-letter country codes um either one is good but just for this one i'm just going to work with that so i'm going to do a left join

because uh we want to join that table on the existing data that is in what we have here and it's going to be gt country pops the data set and we're going to filter that just by those first two columns so country name and what is the other one uh country code two right so we filter that down uh now you just get like those two columns so we'll just make that distinct so we have you know just like you know like 100 or so 170 or so rows and then uh we'll do by because there'll be two different names and i believe construction is the c and then two accorded things this is the left side like are all the revenue table and this is the country pop side so this side is going to be country name and this one will be i think just country yeah country okay let's run this now and see if it works totally works we got country code two in there we'll change all these names later promise you that

uh so we did a left join there's a ton of stuff to do before you get to the table i know but you know we got so much to do we have no choice okay now we're gonna do another mutate okay and the thing we're gonna do here is say okay so we have this ieps i'm gonna stretch this out just a little bit so we can see here um because it's almost impossible to see what we have in terms of types there we go item names so we have like different tiers of gold offer and i think there's not just gold there's also like gems i believe um but we just want to lump them together into like one type so all we gotta do is like take off the digit and we don't have to do any regular expressions or anything just take off the digit um oh no we do have to do regular expression we have to identify the digit and just take it off okay but this is super simple so we're going to call this ip type as a new thing and we're just going to do a g sub then we're going to look for any digit so just zero nine and it's only just one so we don't have to put any star here like that and then we're just going to like replace it with nothing and then it's going to be item name okay let's see that this actually worked great it did an error which is fantastic we got iep type and i'm trusting that this number is going so that sort of lumps things together so we have like no less less dimensions to worry about

okay continuing we're going to select a few things to really narrow down this table so we actually can see our one screen uh so we're going to select a country and that is currently as country code two great and then the other things we're going to select are month ip type and most we need item revenue of course in that order because like these will be things we group on and then the last thing will just be the thing we want to summarize okay let's look at this now great much much shorter much less wide still lots of rows but summary will take care of that

uh summarize well so we're going to group by basically all the things like month uh ip type in country i'm going to pass that into summarize uh we're going to call this total rev and it's just going to be the sum of item revenue and then there's like this groups argument that i always forget to to select or to use and always gives me a warning so i'm just gonna use it now and i think it's drop is what you want okay let's take a look now much less rows i'm hoping no okay sorry i don't use the shortcut because i just never did do that okay much less 765 plus 10 rows 775 that is great

okay so now we're going to arrange stuff it's always good to arrange it sort of see like you know things make sense um so i'm going to arrange by month country and ip type and particularly again great and arranging is actually super important before you get into like gt anyways because you're going to have like arranged data in gt some things you can change though um but it's good to sort of like arrange it you know a bit because it's for display okay now we arranged it we're going to use pivot wider to take the months and put them as columns okay so pivot wider

okay and i believe this is names from and then values from i'm going to select it down here so the names are from month that includes no i don't think you need to put quotes values from total ev great now we're going to see the table being super wide i'm hoping yes so we unfortunately have like column names being numbers but they're in batik so they're okay to access that way and you can actually even in gt access and buy like uh just like like quoted numbers so it's not too bad

Basic gt table

so now we have this we're going to pipe that into gt finally and we'll see how this looks i'm going to bring this up so we can actually see the table okay great so now we have a gt table finally we're going to make this a bit wider so now we can see that we have all this stuff in here which is great it's a bit long but we can totally change this um one thing we might note is that with the structure is fine but we have things which are great for grouping we have like names here for rows and we have groups which are the countries so in the gt call itself we have ronin call and grouping call we use both

so for ronin call we're going to use in quotes it's going to be uh iap type and for gripping call it's going to be country great okay so now running this it gets arranged a little bit differently so now we have it like this which is kind of cool so now we have countries like this they're not arranged in a way that we maybe want it to be arranged but we can sort of fix that

okay oh also i don't want maybe all these countries here because we do have a countries considered so we didn't actually filter before but that's cool because like with uh you know with this code we can definitely just like change it uh so i think it's country at this point yeah country in countries considered yeah we'll join it with pipe now this table because we're just running this code should be plus countries now great that's perfect okay so now it's like less less big of a table it's kind of like focused a bit

Specifying row order with row_group_order()

okay so now we have this we're going to continue on so now we have a table at least so we're in we're in table territory in gt now we can do all sorts of things to like shape it while we're in the gt api um one thing you might want is like the countries to be in order that we want just because uh we decided beforehand you know these are largest more important at the top in terms of revenue there's actually a function in gt that's maybe less well known it's called row group order it's just for changing the order of like these row groups and you just do that by a vector of the names of the row groups and luckily we have that it's basically just countries considered um considered great so now if we run this we should get it in the order yeah exactly usgb de perfect that's what we want and this is important sometimes you want exactly the order you want and it's kind of frustrating to put in that order there's other ways to do it beforehand but this is a nice easy way of doing it in gt

Formatting currency and missing values

great so we have group order now we're gonna do a like a ton of stuff just to like uh make the table present well uh it has lots of things so one thing we might do is format the numbers so they're actually in currencies right now this is just like usd amounts uh but they don't look like that so we'll use format currency and the cool thing about that is you can just use columns equals to everything and then all columns which are here in the body will be formatted as such and you do have like this currency uh argument but it's already set to usd so we don't have to do anything there uh one thing we might do is we don't really need the pennies involved so we just might say use subunits equal or false and let's see what that looks like

all right not bad that's pretty good that's normal you want because like these are big figures you don't really care about the sense it's kind of like you know it's just rounded essentially in this case good okay so now we have that formatting in place um if we scroll down we see we have some any values so while we're doing formatting you can actually use a formatter called format missing so it's fmt missing and if you just use that on everything so the first argument is columns i just use that everywhere okay so use everything and then what we'll do is it'll go in and find every na and just use the default replacement text you can set it but by default it's this m dash which is quite nice um again you can set with any word you can just mark down it's totally up to you but the default is pretty good

Creating row groups as columns with tab_options()

okay so that's where i'm missing um another new feature in gt which is kind of cool um it it's basically in the last release of gt is you can take these row groups and make them columns so it's a little hard to access that it's actually in tab options but i'm going to show you how to do that so it's actually tab options and tab options it's just got so many different options that you probably want to tab to see what they are you can actually search you can actually search do a fuzzy search in here um the option that we need is row group um there it is as column and then you just use a true by default it's false that we want true in this case okay so now it looks like this so we have row groups but now they're to the side and it kind of displays nicely because you just have like this just sort of like these groups these bundles of rows which are nice

Relabeling columns with cols_label()

great so now we have that um the thing we gotta do now is take those numbers in you know the top and make those month names uh and we have that which is great we have this month names list right here and what you can do in um calls label which is the thing you use to relabel the column names is you can pass in a list so it's like this dot list argument so that list will be this right here this month names list so if you just pass that in i believe that's all you gotta do um let's run this yeah now we get the months as like these short three-letter months which is great better than numbers i'd say okay so we have a table it's looking like it's developing pretty well

Creating tab spanners

um one thing we can do and it's always fun to do that is add some context to what these months are or maybe there's special things about these months so you can add spanners above column names we do that with tab spanner right here and just some use if you're using a development version of gt um we now have the ability to have multiple spanners uh previously you can only have like one level spanners but if you're using development version i definitely encourage that um you get multiple spanners which is great i'll show you how to create multiple spanners in a very logical and easy to use way so tab spanner the first thing i'm going to do is well say what year this is i know it's kind of ridiculous but we will say this is label 2015 and this is like fake data i just gave the year 2015 i don't know why uh but that's what it is so we'll then we'll use columns okay and we'll span this over every column with everything like that okay 2015 great

okay uh and since this is fake data i can just make up stuff everywhere but we'll add some more spanners and we'll just say like the first three months there's a certain version of like this this game out like version 1.0 so we'll call this label v 0.1 and the columns won't be everything um they will actually be c and backtick one two and three i'll show you two styles of doing this but these are actual the names of the columns themselves in the original data okay so i'll get rid of this and we'll see that this now appears over those first three columns which is great so now we want to do the rest what version was the next one i think 1.2 they skip 1.1 we'll just put that in okay so 1.2 and we can access columns in a different way we can just say 4 to 12 but they can't be numbers they have to be a character so we'll do this right here as character great so i just just so you know it gives you this so if you run the whole thing we now get this great now we have like two levels of spanners which is kind of cool it gives you extra context about like this is child 15 these are the months and this is some extra information about what version of the game was out during these months

Adding a title and subtitle with tab_header()

okay great now we have that we should put a header in this table so we can identify and you know just give it a nice title and subtitle so we do that with tab header and there's two things you put in here a title and a subtitle subtitle is optional but it's always nice to have and we'll call this revenue amounts by country ip types let's do ip type great subtitle we can make that we can use markdown so inside here we can have markdown text which is and it'll be formatted as such so we'll say this considers so this week bold top eight overall we have to close this off i'll put this down below for clarity like so let's run this and we'll see a title looks good markdown did carry over which is nice

one thing we do is if this is like not enough space between like you know like the the rest of the table we can because we're using markdown we can throw in some like line breaks so vr like so if put in two to actually force like this you know the amount of area but we'll see if this is good some people may like this have a little bit of extra breathing room before you actually get to the table so that's a nice little trick you can do use great so now we have the header

Aligning the header and adding a stubhead label

we could do things like there's these opt functions like opt align table header you may want it to the left so there's an option here just to align it to the left i mean it gives a nice look as long as you style everything else to be sort of like you know to go with this uh it could be good okay uh one thing we're missing is this large gulf of space we don't have to put anything there but it's kind of simple sign there it's basically it's called this is the stub essentially so this is called the stub head we can actually just put a label there and we can also use markdown just like we did before to do that so this is tab stub head and the only argument is label and we'll use markdown and we'll say region and ap type and again if you want to force a line break because we're using markdown you do it right in the middle here if you want you just want to guarantee that this breaks there so let's take a look here great excellent okay so we got that now um now we can style this thing uh quite a bit

Styling the table

because right now it's just like a plain table i mean it looks fine has a lot of information but uh it's not a whole heck of a lot of style here uh so let's style a little bit first and then we'll get into like coloring the data as well because that's always fun and good to do okay so we just have style this is the thing where you target different areas of the table and you apply style okay so in this case i just want to make all the text a little bit smaller in the in the in the body of the table there's kind of overwhelmingly large so i'm just going to do that right now so i'm going to say it's going to be style cell text and we'll say the size there's a bunch of arguments but size is one of them but here's the list of arguments and this is like html thing like a css thing you just say smaller and it'll just make it a bit smaller than the default and with tab style you always have to put in locations so in this case i will use cells body if you're targeting all the cells in the body you have to put any arguments it's already targeting everything so let's run this and we'll see that this becomes just a little bit smaller

yeah and now it actually fits like width wise into like because right now we're just sizing everything by like the size of the content uh but now making it smaller makes it a bit a little bit nicer like these are a bit larger these are maybe less important especially as you color the you know like the cells themselves they become a little bit less important

Coloring cells with data_color()

okay so now we have tab style we did that uh the next thing we do is like i said we're going to color all the cells so we use the call like the function called data color okay really kind of tough to use i always recommend going to the help data color like so i mean i could barely remember how to use it because it involves using scales functions inside of it for the colors argument okay likely there's examples in here and they show how they work but uh it's always a bit of a challenge you know even for me

okay likely there's examples in here and they show how they work but uh it's always a bit of a challenge you know even for me

okay but for this we know we need a few arguments that we see here um so we're going to use uh columns first we're going to use we're going to consider all the columns all the body columns in the table which is great uh and then we're going to use scales column numeric that's a function from scales palette okay this is going to be a little bit strange but i'm using two greens and the first green i'm going to use is six six ff i'll make that capital ff zero zero and this is a little bit strange i use the same color for like you know the high amount except i'm going to use alpha the strange thing about like alpha in scales column numeric is you don't provide alpha value you provide true or false and where you provide the alpha thing is right here in the color itself so you can make color names like have an alpha part so zero alpha is is there so this is like the low value and the complete opaque one is ff okay very strange the way you do it but it makes sense it just says whether you consider the alpha part of the color

okay okay great uh so and also we're going to choose an na color um just a random color okay maybe one more f and six six is that right one two three four five six seven eight okay good and what else oh yeah the most important one is domain and this is where you can choose the limits like the range of like where the colors go if you just want it to be the data itself you can just use null okay that simplifies things a bit okay is that it i hope that's it but yeah it seems like that's it so you didn't provide columns you need to provide like a function here uh this argument is called colors unfortunately uh but if you have that then you're good to go so i'm going to like run this and hope that it just works

okay it does which is great so we can see here that like the values here are colored um dark greens are like high values these are like you know like low sort of like most transparent greens are like less values so just the way to sort of map around you know see if revenue has grown during you know months that we've you know like had the game and uh you know which regions like the revenue is not so great you see here and any color is right here so basically any any values are in this color uh so that's good otherwise i think it'd be a dark gray and maybe that's just not driving with the color scheme here

Adding source notes and footnotes

okay so that's the color great uh so now we're going to do things like fill out the table a bit more uh so we're going to add source notes so you do that with add with start with tab source note and for each source source note you add you you basically make a new call of tab source note okay and the argument here is source note and again you can use markdown for this and we can just say like the source of the data we just got this is all pretend we'll just say all revenue uh figures obtained uh from daily retrievals from the again we have markdown so we'll just say api is a period i believe that closes it off let's run this okay let me have to go right to the bottom to see it there it is which is great and this is italicized which is fantastic okay so we're going to keep keep going with this

uh we'll add another source note just to show you that you can add a whole bunch and the order that you specify them in uh and this one will say yeah let's go start with all it's gonna like deliver this yeah all reporting uh ship here was created by the and again you can use like crazy markdown like this italics and bold uh we'll say central or data science team so let's run this and again we'll scroll to the bottom and see that it was added and it's in the same order which is wonderful

and we're going to add some footnotes now we're just going to fill out this footer and then we can sort of see that you know like interesting things could be like uh shown there and like you can have footnote references in the table and you know it kind of like adds a bit more context where you might need it so just tap footnote uh in this case you need an argument which is footnote and locations so it's kind of like test style where you need the locations so i'm just going to put that in for now but the footnote here might be um well let's maybe like put footnotes on like where there's like missing data and we'll explain it i think that's not a bad idea okay we'll say that these figures are zero dollars or less we can say due to refunds yeah which is totally possibility um and locations so if you have multiple locations like we have two different columns we can make a list of locations like so and we just you know separate the each of the like cells calls with a comma

okay so cells body and we'll say first one is in columns equal to one that's our original column name and we have to sort of like say which rows they are and in this case we'll say rows equals is na and like so unfortunately we have to do it twice um because we have two different columns and we can't just refer to the column like in this rows expression uh but you know it's not too bad that maybe that may change later on so in this case we know there's one in month three so we have to do this great and hopefully this works i'm going to run it to see if it does okay it didn't complain and we do see a footnote right there great and we do see it in the right places it's not anywhere else besides the na's uh which is great i love that

okay more footnotes yeah i mean like just having one footnote is not great so we're gonna add a few more i know it's a little bit tedious but um you're gonna love all the footnotes i swear to you okay tab foot great okay in this case um let's see it was a good one um something notable okay right here norway like there's a huge jump in like the revenue i mean maybe you should explain this okay so let's do that let's target this cell with a footnote and some explanation so footnote it's going to be um we'll make this markdown just for fun a surprising jump in jumps in bold uh revenue from the previous month okay period we'll put a comma so on the outside is that right yes and now we need a location so let's say locations is going to be cells body columns will be the 12th month okay and this one's a bit tricky because usually you can specify by like the like the label here but they're all the same which is like makes it impossible it's just gems gold offer gems gold offer okay so we can't do that so we have to actually use an expression and we have to like make sure it is just for this cell which is not great but we will do it so we'll do we'll say rose is going to equal because it's on that column um basically just how we got the value we'll just put the value in round 12 equal to 6278 okay that means you know i mean i can't think of another way to do it so but this is not bad this is not bad yeah i see it's right there and it's nowhere else because no other value is that value

great good so now we have two footnotes i specified you know in the order i wanted and it just appeared in the right order which is awesome gotta have it okay now we're going to add even more for this oh my god but we can explain what these version numbers are and i swear we're going to get we're going to finish the footnotes after that um because i like to have a bunch of footnotes because you know more numbers and we can do more stuff in there like i said before so tab footnote note is going to equal um we'll just say like the and i'll put this in back text i'll make it a code font like so we'll say the version 1.0 build used the first version of the offer agent sdk uh because we're going to explain that you know the offers were pretty bad up until like the second version came out just coincidentally it's kind of like they picked up so we'll say the offer system is was broke initially okay so we got that put a comma on the outside because this is the markdown part uh locations and this will be cells colon spanners and this is going to be spanners equal to exactly the label we're in 1.0 uh this is actually the id uh but the label becomes the id so and you can specify an id if you want but usually you just want the label to be the id for you know easiness is sake okay we do the exact same thing i'm just going to copy this to explain the 1.2 part and it's really just like changing this um say the 1.2 build what did it do it added more well it got better um let's say it added more missions basically get free dlc uh more missions and had an updated offer agent sdk great that's closed off and we'll say spanners 1.2 that's what's called okay so i'm gonna run this and we should get way more footnotes than we've ever seen uh four minutes great i see them here one two and then there should be like a third here great and then repeating fours and there they all are great this is so good

i'm loving this table so far i mean it looks so great i mean oh man this is fake yeah i wish it was real yeah because like this is too good to be to be fake okay anyways so let's keep going

Column widths and padding

um one thing i like to do is change the widths of all the columns like just right away i don't want i don't want to be left up to chance okay so i'll just say everything is going to be 75 pixels wide and let's take a look at that this is something you do and you you just adjust it all the time oh no it does not work yeah okay so you gotta be careful here not to use just everything it's not a column name great thank you um yeah now we should see yes this looks great now everything is that width which is perfect um here's a crazy trick um it's a trick where like you want to specify the column widths of these but they don't come with column names really um you can just use a number like one and now i'll actually refer to this not this it's a little strange but but column widths assumes everything is is a column now and we're just going to change everything so we do one and make this a bit smaller so px 50 comma okay so now that first one should be narrowed down if we see it shrunk down a little bit which is good

okay a recent version of gt add a bunch of new functions for padding they're all in opt the opt series of functions one's called opt horizontal padding and we're going to do a thing where we scale it to be um you know like more padding and i'll show you where i'm going with this because we have like all the values like we're butting up against the edge you know a little bit of space but we want to maybe center it a bit i think it might look nice so let's try it so this will take all the data in here basically all the cells it will just sort of bring stuff in see now it's more toward the center but still right aligned it's kind of nice and this is actually brought in as well so everything lines up it's really nice like everything's one function it just scales the padding and this can be between uh zero and one as well if you want it you know to be like less padding so that's how that works

okay uh while we're on the padding tip uh we just use opt vertical padding as well because you know why not and we'll try to get this like a bit a little more dense so we'll say the scale in this case is smaller but we want less padding in the vertical direction okay so we should see a bit of a tightening which is great which is great i'm gonna make this a bit bigger so you can see more of this good this is really shaping up

Styling row groups and fonts

okay so we can do the padding thing and now we want to do even more style stuff it's um i guess we'll do some more tap style um because i think what we want to change now is the row groups themselves yeah we want to maybe differentiate like these like categories so let's do that right now so we'll say tap style and uh we'll make we'll make it on the locations which equals to cells row groups and this just means all of them and the first argument is actually the style itself we want to change the text and the background so we'll do put it in a list make sure there's a comma uh cell text we'll say the color of the text is going to be a css color called snow the weight will make it bold uh the weight will make it bold and we'll align it to the right it may not make much of a difference but let's try it okay so we have that um now we'll do cell fill and now we want the color to be slate gray i'm doing caps because that's how it is in css but you can do in all lowercase it's the same thing and we'll add an alpha that's actually an argument here of 0.5 so it blends a bit nicely with the background we may add in the future okay so let's add this it takes a little while but it's worth it so now we have this great good stuff

uh now we'll do another thing there's like this another opt function called opt all caps it just adds a bit more style it makes the surrounding chrome in a sort of like caps type of style like a small caps it's not too bad okay i sometimes add that because it's kind of nice and now uh we can change the font with opt table font uh and we can use the font which is a google font and we can just choose a name and i know there's a bunch there's a few ones one i like is carla we'll add that in we'll see immediate change in the table looks really good i kind of like this

Final table options

and now to finish it off we'll just add like a ton of like different options uh in the table because there's so many things you can do uh i might go very quickly through this but options i recommend hitting tab you can search through there's little descriptions here um but we'll just change things to make things a little bit nicer in the table uh so we'll do the table background color there and we'll choose lemon chiffon uh great okay good that's a you know maybe a bit too too bright one thing we can do we have this function in gt called adjust luminance we can wrap the color in it and there's an argument there which i believe is called steps and we can make that two and this could be totally adjusted uh to suit what you think is good okay great i'm gonna make this a little bit bigger so we can see the rest okay great so that's that

i'm gonna make even more options here uh so heading background color i'm gonna do the same sort of thing uh except i'll just keep lemon chiffon without the change um the other thing i'll try is uh footnotes background color so i'm just changing a bunch of background colors here uh i'm just gonna put them in here and then change them all at once okay footnotes and then i want source notes background color great just prepping it up what else could we do we can just copy this here and just change the amount of steps it's not a bad thing then we have a variation on like one color so in this case i think i might bring it back minus 0.5 and maybe the same thing here because they're actually separate locations i'm going to run this to actually see what's going on there and we'll zoom to the bottom so you can see what colors have been changed okay so right here it's a bit darker um it's kind of like almost similar to this great

okay a few more things and i swear this will do it uh so you might want to do a thing where you cap the table on the top and bottom you can change the table border like the very top and bottom border so i think it's table border um let's do top uh width yeah and we can use the function px to find pixels just put it there and we do the same thing with the table border bottom width great so now we have those okay another thing we do is footnotes there's this multi-line option now in gt right now there's there are multiple lines by default we can just say false and it'll appear as one paragraph which is kind of cool another cool thing we can do is table body h lines style we can change the style of the lines themselves because there's quite a few lines uh we'll just make it dotted you know it's just dashed and you know solid is the default um what else we can change the heading title font size do something pretty big x 30 and we do the same thing with the heading subtitle font size make that a bit smaller this just bumps up in size okay after all this let's take a look at our table this may be the final table i mean i did a lot to this

so let's make this a little wide we sort of see what we've done this is now huge but it's nice because it's a bit bigger than the rest makes it more title like uh this looks pretty good see the dots there's different size of dots a little hard to see because the contrast but you know it sort of lightens things a bit and again we have the footnotes they're all one paragraph uh just for the footnotes part the source notes you can change the way that that is laid out uh but in this case we did not do that we just have them as you know separate lines it's multi-line equals true but we can set that to false if you want a paragraph yeah and this is our table uh not too bad if you have real data it's even better uh but fake data is always great to have because you know what you're going to do you don't have data you need to you need to get some so okay so that's my uh my that's my gt demo for today hope you enjoyed

yeah and this is our table uh not too bad if you have real data it's even better uh but fake data is always great to have because you know what you're going to do you don't have data you need to you need to get some