Football predictions table
Hello !
Welcome to this 4th football post. For better visibility, I advise you to look at my posts on a computer (for the size but also because the colors differ on a phone that has a dark theme like me. If the theme is light, only the size makes it difficult to read).
Today it will once again be about building a table with the gt package
. But this time, we will see new features, such as adding color gradients to columns or adding images.
For this table, we will use data corresponding to the matches of the French championship of the first division (fake data concerning the variables linked to the result probabilities).
I will not talk about the features already seen previously so I advise you to take a look before at this post
if you are not not yet comfortable with the gt package, although this last post is not a lesson....
The data, images, and the code are given at the end of the post with a compressed file.
Firstly, we import the data with for example the read_delim() function.
The data are as follows:
Raw and therefore very minimalist visually. So we're going to use the gt package to make this all prettier.
To do this, we need the logos of the teams present in this table, and 2 images to replace the "Yes" and "No" values. I took all these images from Fotmob
and flaticon
.
Now we can look at the code with the new features. Firstly, the text_transform() function, which will replaces here the team texts with team logos.
The second new feature is the data_color() function, which will creates here a color gradient for selected columns (result probabilities).
Then, I simply modified the css code obtained via the inspect code option when I look at my gt table on the web page, in order to have a slightly personalized visual. Finally, I took a screenshot of the web page containing the gt table using the webshot2
package.
We get :
You will find the code below by clicking the github link button.
Thanks for reading! I hope it was clear and you liked it.
If you have any questions or remarks, I invite you to create an account (it's free) to write a comment, or simply to be notified of a new post in the future !
I apologize if all the images are not zoomed in the same way, I have not yet found the appropriate method ! ๐ฃ
See you soon for new content ๐
Comments ()