The rghcard action draws the cards on GitHub’s machines, with no R on your computer: Get started sets it up. rghcard draws the same cards in R, on your computer, one function at a time, and you choose what goes into them and where they go. This article goes through it step by step, from installing rghcard to the cards on your profile. Its code runs as it is: copy it into the console of RStudio, Positron or R.
Install rghcard
install.packages("rghcard", repos = c(
"https://sedzinfo.r-universe.dev",
"https://cloud.r-project.org"
))This also installs the packages that rghcard needs: gh, which reads from GitHub, and rsvg, which turns a card into a PNG. The README has the other ways to install it, and how to install R.
Try it with made-up statistics
library(rghcard)
stats <- example_stats()
stats
#> GitHub statistics of example-user, collected until 2026-12-03
#> 8 repositories, 101 stars, traffic from 2026-11-03 to 2026-12-02, 4,132 contributions since 2019-03-14
#> Tables: repos (8 rows), views (240 rows), clones (240 rows), traffic (8 rows), referrers (12 rows), pages (9 rows), releases (4 rows), actions (87 rows), languages (15 rows), stars (101 rows), profile (1 rows), contributions (2822 rows), commits (69 rows), contribution_types (8 rows)example_stats() returns the statistics of a made-up
user, example-user, so that you can try every card without
a token. The first line says whose they are and when they were
collected; the last lists the tables of their history, which Charts of your own uses.
stats_card() draws their statistics card into a file:
stats_card(stats, "rghcard-stats.svg")The file is in the working directory, which getwd()
shows and setwd() changes, or wherever its path says, such
as "cards/rghcard-stats.svg"; a folder that does not exist
yet is created.
See the card
view_card() shows the card in the Viewer pane of RStudio
or Positron:
view_card("rghcard-stats.svg")The Viewer shows it as a web page: sharp at any size, shrunk to fit
the pane, and telling the value of each column and bar when you point at
it. In R on its own, view_card() opens your web browser
instead. The Plots pane shows the card as a picture, as a GitHub profile
does:
view_card("rghcard-stats.svg", "plots")view_card() takes what the card functions return, so it
also shows a card as it is drawn, into a file or, with
file = NULL, without one:
view_card(stats_card(stats, "rghcard-stats.svg"))
view_card(stats_card(stats, file = NULL), "plots")The six cards
Each card has its function, with its own key figures and charts:
| Function | What the card shows |
|---|---|
contributions_card() |
The contributions, commits and streaks of the user, and the languages they commit in. |
stats_card() |
The stars, page views, clones, release downloads and GitHub Actions runs of their repositories. |
activity_card() |
Their pull requests, issues, reviews and followers, and their contributions by type and by day of the week. |
visitors_card() |
The unique visitors and cloners of the last 14 days, the sites that sent them and the pages they viewed. |
actions_card() |
Their GitHub Actions runs: how many succeeded and failed, how long they took, and the busiest workflows. |
code_card() |
The size of their code in each language, their largest repositories, their stars month by month, and their forks and watchers. |
contributions_card(stats, "rghcard-contributions.svg")
stats_card(stats, "rghcard-stats.svg")
activity_card(stats, "rghcard-activity.svg")
visitors_card(stats, "rghcard-visitors.svg")
actions_card(stats, "rghcard-actions.svg")
code_card(stats, "rghcard-code.svg")The contributions card, The statistics card and More cards show each card and explain each of its numbers.
Choose the charts
Under its key figures, a card has one to three charts, which
panels chooses. Any card can show any of the 23 charts,
whichever card they come from. One chart takes the whole width of the
card:
stats_card(stats, "rghcard-views.svg", panels = "views")Two or three share it, in the order given. Here the code card shows the bytes of code per language next to the commits per language, a chart of the contributions card:
These are the charts, under the card that shows each of them by default; the article of each card explains them:
| Card | Chart | What it shows |
|---|---|---|
| Contributions | "contributions" |
Contributions per month, in the last 12 months |
"commit_languages" |
Commits per language, as a ring | |
"languages" |
Repositories per main language, as a ring | |
| Statistics | "views" |
Page views per day |
"clones" |
Clones per day | |
"actions" |
GitHub Actions runs per day | |
"top_viewed" |
The five repositories with the most page views | |
"top_cloned" |
The five repositories with the most clones | |
"top_starred" |
The five repositories with the most stars | |
| Activity | "contribution_types" |
Contributions by type, as a ring |
"weekdays" |
Contributions per day of the week, in the last 12 months | |
"top_committed" |
The five repositories with the most commits of the user | |
| Visitors | "visitors" |
Unique visitors per day |
"referrers" |
The five sites that sent the most page views | |
"top_pages" |
The five most viewed pages | |
| GitHub Actions | "top_workflows" |
The five workflows with the most runs |
"run_time" |
The five repositories whose runs took longest | |
"top_failed" |
The five workflows with the most failed runs | |
| Code | "code_languages" |
Bytes of code per language, as a ring |
"stars_history" |
Stars at the end of each month, in the last 12 months | |
"largest" |
The five repositories with the most code | |
"top_forked" |
The five repositories with the most forks | |
"top_watched" |
The five repositories with the most watchers |
A name that rghcard does not know stops the card, with the list of them all:
stats_card(stats, "rghcard-stats.svg", panels = "view")
#> Error:
#> ! `panels` must be one to three of: views, clones, actions, top_viewed, top_cloned, top_starred, languages, contributions, commit_languages, contribution_types, weekdays, top_committed, visitors, referrers, top_pages, top_workflows, run_time, top_failed, code_languages, stars_history, largest, top_forked, top_watched.Theme, days, title and size
These options change a card:
-
theme = "light"draws the card in the colours of GitHub’s light mode, and"dark", the default, in those of its dark mode. -
dayssets the days of the page views, clones and runs ofstats_card()and of the runs ofactions_card(): the last 30 by default. -
titlereplaces the user name and the name of the card at the top left. -
widthis the width of the card in pixels, 900 by default; its height follows.
actions_card(stats, "rghcard-actions-light.svg", theme = "light",
days = 14, title = "My workflows", width = 700)SVG, PNG or SVG code
The end of the file name chooses the format:
-
.svg: sharp at any size, and about a tenth of the size of a PNG. Its text takes the fonts of the screen that shows it, as GitHub’s own pages do. -
.png: a picture, for places that take no SVG files, such as some social networks and slides. Its text takes the fonts of your computer, and it has twice as many pixels aswidth, so that it stays sharp on high-resolution screens. -
file = NULL: no file but the SVG code, to put the card into a web page that R makes, such as an R Markdown or Quarto document, as this article does, or a Shiny app:
# in a chunk of an R Markdown or Quarto document
knitr::raw_html(stats_card(stats, file = NULL))
# in the user interface of a Shiny app
shiny::HTML(stats_card(stats, file = NULL))A card is 900 pixels wide, so on a narrower screen it needs this CSS, as in this article, to shrink with the page:
Your own statistics
A token
GitHub shows the page views and clones of a repository only to those
who can push to it, so collect_stats() reads them with a
token of yours: a password that lets a program read from GitHub for you.
The gh package, which rghcard uses, finds it by itself, if you have one.
See whether you do:
gh::gh_whoami()It prints your user name and the scopes of your token, or says that
there is no token. Then create
one with this link, which fills in GitHub’s form: the name
rghcard and the scope repo, which the page
views and clones need. Choose when it expires, click Generate
token, copy the token, and give it to R:
gitcreds::gitcreds_set()It asks for the token and keeps it in the credential store of your
computer, where gh, and git, find it in every R session.
gitcreds_set() needs git; without it, put the token
into the file .Renviron of your home folder, which
file.edit("~/.Renviron") opens, as the line
GITHUB_PAT= followed by the token, and restart R. Never
write a token into a script, which others may read: anyone who has it
can act as you on GitHub. When the token expires, create another the
same way.
A fine-grained token, such as the one of the rghcard action, works too, with the permission Administration: Read-only, but GitHub then leaves out your private contributions, so the cards can count fewer contributions than your profile. The action keeps them: it reads the contributions with the token GitHub gives each workflow, which your computer does not have.
Collect your statistics
stats <- collect_stats()
statscollect_stats() reads the repositories you own, the
public ones that are not forks, and your contributions since you joined
GitHub: a minute or two for a few dozen repositories. It keeps them as a
history of CSV files in the folder rghcard-data, in the
working directory, and returns them, for the cards to draw:
contributions_card(stats, "rghcard-contributions.svg")
stats_card(stats, "rghcard-stats.svg")The cards also take the folder of the history in place of the
statistics, rghcard-data by default, so in the working
directory of the collection, stats_card() alone draws
rghcard-stats.png from it.
include_private = TRUE and
include_forks = TRUE add the private repositories and the
forks, which are left out because cards are usually public. The help
page of collect_stats() describes every argument and every
table.
Keep the history
GitHub keeps the page views and clones for 14 days only, so a card
can cover more days only when the history has them: run
collect_stats() at least once a week, with the same folder,
and each run adds the days since the one before. dir
chooses the folder; keep using the same one. read_stats()
reads the history again, without asking GitHub, as in a new R
session:
stats <- read_stats("rghcard-data")
stats_card(stats, "rghcard-stats.svg", days = 90)Until the history has 90 days, the card covers the days it has, and says so. The rghcard action collects every week on GitHub’s machines, so that no week is missed: Get started sets it up.
Another user
For another user, collect_stats() collects what GitHub
shows to everyone with a token: repositories, stars, forks, languages,
release downloads, GitHub Actions runs and contributions, but no page
views, clones or visitors, nor when each star came.
dir = NULL keeps nothing on disk:
octocat <- collect_stats(user = "octocat", dir = NULL)
view_card(stats_card(octocat, file = NULL))Cards from a user name goes through it, with what a user name brings without a token, and a Shiny app that draws the card of any user name.
Charts of your own
The statistics are a list of data frames, one for each table of the history, so any chart of R can draw them. The page views, for example, have a row for each repository and day:
head(stats$views)
#> repo date count uniques
#> 1 tidysurvey 2026-11-03 18 10
#> 2 tidysurvey 2026-11-04 11 6
#> 3 tidysurvey 2026-11-05 8 5
#> 4 tidysurvey 2026-11-06 21 9
#> 5 tidysurvey 2026-11-07 10 6
#> 6 tidysurvey 2026-11-08 4 3Their sum per day, without the day of the collection, which GitHub was still counting, drawn as columns in the blue of the light cards:
updated <- attr(stats, "updated") # the day of the collection
views <- stats$views[as.Date(stats$views$date) < updated, ]
views <- aggregate(count ~ date, data = views, FUN = sum)
days <- format(as.Date(views$date), "%d %b")
barplot(views$count, names.arg = days, col = "#257de0", border = NA,
las = 1, main = "Page views per day")
The contributions of each year since the user joined GitHub, from the table of the contributions per day:
contributions <- stats$contributions
contributions$year <- substr(contributions$date, 1, 4)
per_year <- aggregate(count ~ year, data = contributions, FUN = sum)
barplot(count ~ year, data = per_year, col = "#257de0",
border = NA, las = 1, xlab = "", ylab = "",
main = "Contributions per year")
The help page of collect_stats() describes every table,
and ggplot2, or any other package of charts, draws them as well.
On your profile
GitHub shows on your profile the README of the repository named after your user name. To show the cards there without the rghcard action, draw them, in both themes, into a copy of that repository on your computer:
profile <- "path/to/your/profile/repository"
for (theme in c("dark", "light")) {
contributions_card(stats, theme = theme, file = file.path(
profile, paste0("rghcard-contributions-", theme, ".svg")))
stats_card(stats, theme = theme, file = file.path(
profile, paste0("rghcard-stats-", theme, ".svg")))
}Add them to its README.md, each in a
<picture> that shows each reader the card of their
mode, as Get started
shows, then commit and push. The cards are then public, while the
history can stay on your computer. They change only when you collect and
draw them again; the rghcard action does both every week.