you are viewing a single comment's thread
view the rest of the comments
[โ€“] 33 points 2 years ago* (last edited 2 years ago) (6 children)

statistia-netcontrib.csv

country,netcontrib
DE,25572
FR,12380
NL,6929
IT,3337
SE,2826
DK,1766
AT,1540
FI,1109
IE,703
MT,-14
CY,-172
SI,-386
EE,-729
LT,-860
SK,-1398
LV,-1544
BG,-1727
HR,-1746
ES,-1946
LU,-2020
CZ,-2853
BE,-2950
PT,-3132
RO,-4096
HU,-4206
GR,-4278
PL,-11910

eu-contribution-per-capita.r

if (!require("pacman")) install.packages("pacman")
pacman::p_load(
            countrycode,
            dplyr,
            ggdark,
            ggplot2,
            r2country
        )

abs <- read.csv("statista-netcontrib.csv",header = TRUE)
abs2 <- cbind(abs,name = countrycode(abs$country,"iso2c","country.name")) 

df <- inner_join(country_names, abs2)
df2 <- inner_join(country_population, df)
df2$percap <- df2$netcontrib/df2$population2023*1000000

df3 <- arrange(df2,percap)

ggplot(df3, aes(x = percap, y = reorder(name, percap))) +
    geom_bar(stat = "identity") +
    dark_theme_gray() +
    ylab("Country") +
    xlab("Euros per capita") +
    scale_x_continuous(breaks = scales::pretty_breaks(n = 20)) +
    geom_text(aes(label = percap))

ggsave("euros-percap.png")

Full size image

Sorry about the broken escaping of the angle brackets (โ€œ<โ€ is โ€œ&lt;โ€) in the source; Lemmy is, regrettably, broken on that at the moment.

EDIT: Fixed Latvia country code error.

EDIT2: And Austria country code error.

  • source
  • parent
  • hideshow 6 child comments
  • [โ€“] 13 points 2 years ago* (last edited 2 years ago) (2 children)

    Also, a Markdown table rendition:

    eu-contribution-per-capita-markdown.r

    if (!require("pacman")) install.packages("pacman")
    pacman::p_load(
                countrycode,
                dplyr,
                r2country,
                simplermarkdown
            )
    
    abs &lt;- read.csv("statista-netcontrib.csv",header = TRUE)
    abs2 &lt;- cbind(abs,name = countrycode(abs$country,"iso2c","country.name")) 
    
    df &lt;- inner_join(country_names, abs2)
    df2 &lt;- inner_join(country_population, df)
    df2$percap &lt;- df2$netcontrib/df2$population2023*1000000
    
    df3 &lt;- arrange(df2,-percap)
    
    md_table(df3)
    

    name percap
    Netherlands 386.91124
    Germany 302.86855
    Denmark 297.09908
    Sweden 267.98643
    Finland 199.90810
    France 181.71677
    Austria 168.68113
    Ireland 136.52768
    Italy 56.76638
    Malta -26.94577
    Spain -40.25217
    Slovenia -182.27546
    Cyprus -187.34343
    Romania -214.99549
    Belgium -250.73894
    Slovakia -257.60767
    Bulgaria -267.84703
    Portugal -299.21568
    Lithuania -300.05251
    Poland -315.86485
    Greece -408.10926
    Hungary -438.25808
    Croatia -449.01298
    Estonia -533.72029
    Latvia -819.79399
    Luxembourg -3056.85909
  • source
  • parent
  • hideshow 2 child comments
  • [โ€“] 11 points 2 years ago* (2 children)

    statistia-netcontrib.csv is using some weird country code that isn't ISO 3166-2, because it's got what I assume to be Latvia with the code LA which is actually Laos, and that's reflected on your chart too โ€“ I was initially a bit puzzled as to why Laos was listed as being in the EU. At a quick glance it seems to be the only weird one though

  • source
  • parent
  • hideshow 2 child comments
  • [โ€“] 6 points 2 years ago* (last edited 2 years ago) (1 child)

    That's just me not knowing my country codes. Over here, "LA" is generally Los Angeles. I'll fix it; thanks.

    EDIT: Also, Austria appears to be "AT" rather than "AU". One more fix.

  • source
  • parent
  • hideshow 1 child comment
  • [โ€“] 1 point 2 years ago

    Ah I thought you pulled that from some Eurostat database and they were using wonky country codes. The AU / AT mixup is a classic one, and since the spelling of Austria and Australia is so close it's easy to miss that mistake โ€“ just like I did

  • source
  • parent