Skip to contents

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")
GitHub statistics of example-user Repositories: 8 (public), Stars: 101 (total), Page views: 1.1K (last 30 days), Clones: 1.4K (last 30 days), Release downloads: 599 (all time), Actions runs: 86 (last 30 days), 3 Nov – 2 Dec 2026.example-user· GitHub statistics3 Nov – 2 Dec 2026Repositories8publicStars101totalPage views1.1Klast 30 daysClones1.4Klast 30 daysRelease downloads599all timeActions runs86last 30 daysPage viewsper day, last 30 days0204060801003 Nov 2026: 47 page views4 Nov 2026: 30 page views5 Nov 2026: 26 page views6 Nov 2026: 53 page views7 Nov 2026: 22 page views8 Nov 2026: 9 page views9 Nov 2026: 37 page views10 Nov 2026: 38 page views11 Nov 2026: 33 page views12 Nov 2026: 32 page views13 Nov 2026: 29 page views14 Nov 2026: 14 page views15 Nov 2026: 20 page views16 Nov 2026: 52 page views17 Nov 2026: 36 page views18 Nov 2026: 40 page views19 Nov 2026: 39 page views20 Nov 2026: 82 page views21 Nov 2026: 23 page views22 Nov 2026: 15 page views23 Nov 2026: 43 page views24 Nov 2026: 55 page views25 Nov 2026: 39 page views26 Nov 2026: 37 page views27 Nov 2026: 61 page views28 Nov 2026: 16 page views29 Nov 2026: 22 page views30 Nov 2026: 33 page views1 Dec 2026: 47 page views2 Dec 2026: 42 page views823 Nov2 DecClonesper day, last 30 days0501003 Nov 2026: 51 clones4 Nov 2026: 68 clones5 Nov 2026: 51 clones6 Nov 2026: 57 clones7 Nov 2026: 25 clones8 Nov 2026: 24 clones9 Nov 2026: 43 clones10 Nov 2026: 66 clones11 Nov 2026: 67 clones12 Nov 2026: 48 clones13 Nov 2026: 60 clones14 Nov 2026: 25 clones15 Nov 2026: 22 clones16 Nov 2026: 62 clones17 Nov 2026: 65 clones18 Nov 2026: 58 clones19 Nov 2026: 48 clones20 Nov 2026: 86 clones21 Nov 2026: 19 clones22 Nov 2026: 22 clones23 Nov 2026: 48 clones24 Nov 2026: 65 clones25 Nov 2026: 45 clones26 Nov 2026: 48 clones27 Nov 2026: 41 clones28 Nov 2026: 19 clones29 Nov 2026: 19 clones30 Nov 2026: 64 clones1 Dec 2026: 58 clones2 Dec 2026: 52 clones863 Nov2 DecMost viewed repositoriespage views, last 30 daystidysurveytidysurvey: 434 page views434plotkitplotkit: 202 page views202shiny-weathershiny-weather: 143 page views143websitewebsite: 114 page views114workshop-2026workshop-2026: 88 page views88Clones include automated ones: GitHub Actions runs, package builders, app deployments.rghcard · updated 3 Dec 2026

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")
GitHub statistics of example-user Repositories: 8 (public), Stars: 101 (total), Page views: 1.1K (last 30 days), Clones: 1.4K (last 30 days), Release downloads: 599 (all time), Actions runs: 86 (last 30 days), 3 Nov – 2 Dec 2026.example-user· GitHub statistics3 Nov – 2 Dec 2026Repositories8publicStars101totalPage views1.1Klast 30 daysClones1.4Klast 30 daysRelease downloads599all timeActions runs86last 30 daysPage viewsper day, last 30 days0204060801003 Nov 2026: 47 page views4 Nov 2026: 30 page views5 Nov 2026: 26 page views6 Nov 2026: 53 page views7 Nov 2026: 22 page views8 Nov 2026: 9 page views9 Nov 2026: 37 page views10 Nov 2026: 38 page views11 Nov 2026: 33 page views12 Nov 2026: 32 page views13 Nov 2026: 29 page views14 Nov 2026: 14 page views15 Nov 2026: 20 page views16 Nov 2026: 52 page views17 Nov 2026: 36 page views18 Nov 2026: 40 page views19 Nov 2026: 39 page views20 Nov 2026: 82 page views21 Nov 2026: 23 page views22 Nov 2026: 15 page views23 Nov 2026: 43 page views24 Nov 2026: 55 page views25 Nov 2026: 39 page views26 Nov 2026: 37 page views27 Nov 2026: 61 page views28 Nov 2026: 16 page views29 Nov 2026: 22 page views30 Nov 2026: 33 page views1 Dec 2026: 47 page views2 Dec 2026: 42 page views823 Nov2 DecClones include automated ones: GitHub Actions runs, package builders, app deployments.rghcard · updated 3 Dec 2026

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:

code_card(stats, "rghcard-code.svg",
          panels = c("code_languages", "commit_languages"))
GitHub code of example-user Code: 1.1 MB (in 8 repositories), Languages: 10 (mostly R), Stars: 101 (+38 in 12 months), Forks: 19 (total), Watchers: 18 (total), 3 Dec 2026.example-user· GitHub code3 Dec 2026Code1.1 MBin 8 repositoriesLanguages10mostly RStars101+38 in 12 monthsForks19totalWatchers18totalLanguages by code sizebytes of code per languageR: 731 KB of code (63.6%)TeX: 238 KB of code (20.7%)HTML: 59.8 KB of code (5.2%)Python: 41.2 KB of code (3.6%)C++: 37.3 KB of code (3.2%)Other: 41.2 KB of code (3.6%)1.1 MBof codeR63.6%TeX20.7%HTML5.2%Python3.6%C++3.2%Other3.6%Languages by commitscommits per repository languageR: 1,781 commits (71.8%)Python: 267 commits (10.8%)HTML: 205 commits (8.3%)TeX: 155 commits (6.3%)Shell: 71 commits (2.9%)2.5KcommitsR71.8%Python10.8%HTML8.3%TeX6.3%Shell2.9%Code as GitHub's language bars count it: without documentation, vendored or generated files.rghcard · updated 3 Dec 2026

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.
  • days sets the days of the page views, clones and runs of stats_card() and of the runs of actions_card(): the last 30 by default.
  • title replaces the user name and the name of the card at the top left.
  • width is 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)
GitHub Actions of example-user Runs: 42 (last 14 days), Succeeded: 90% (of 42 finished), Failed: 4 (last 14 days), Run time: 4.9 h (last 14 days), Workflows: 4 (in 4 repositories), 19 Nov – 2 Dec 2026.My workflows19 Nov – 2 Dec 2026Runs42last 14 daysSucceeded90%of 42 finishedFailed4last 14 daysRun time4.9 hlast 14 daysWorkflows4in 4 repositoriesGitHub Actions runsper day, last 14 days0246819 Nov 2026: 7 runs20 Nov 2026: 3 runs21 Nov 2026: 2 runs22 Nov 2026: 2 runs23 Nov 2026: 4 runs25 Nov 2026: 3 runs26 Nov 2026: 4 runs27 Nov 2026: 2 runs28 Nov 2026: 2 runs29 Nov 2026: 4 runs30 Nov 2026: 3 runs1 Dec 2026: 3 runs2 Dec 2026: 3 runs719 Nov2 DecBusiest workflowsruns, last 14 daysR-CMD-checkR-CMD-check: 30 runs30pages build and deploymentpages build and deployment: 8 runs8Deploy appDeploy app: 4 runs4Run time by repositorystart to end of the runs, last 14 daystidysurveytidysurvey: 2.7 h of runs2.7 hplotkitplotkit: 1.8 h of runs1.8 hshiny-weathershiny-weather: 16 min of runs16 minwebsitewebsite: 8 min of runs8 minRun time: from the start of each run to its end, not the minutes GitHub bills.rghcard · updated 3 Dec 2026

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 as width, 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:

svg[role="img"] { max-width: 100%; height: auto; }

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()
stats

collect_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       3

Their 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")

Columns of the page views of example-user per day, from 3 November to 2 December 2026: mostly 20 to 45 a day, 82 at most.

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")

Columns of the contributions of example-user per year, rising from 33 in 2019 to 1,170 in 2026.

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.