4

I'm trying to make a graph like the one on the picture in R. I tried with this piece of code, however it doesn't look the same, I want it to be symmetrical just like the one on the picture.

My data.frame looks like this:

Group    Ranking1    Ranking2     Pop
  a           1            1      12345
  b           2            4      127868
  c           3            2      123477
  d           4            3      9485
  e           5            7      132588
  f           6            5      38741
  g           7            9      8372
  h           8            11     53423
  i           9            6      238419
  j           10           16     31314

And the code I used was:

ggparcoord(data,
columns = 2:3, groupColumn = 1, 
scale="globalminmax",
showPoints = TRUE, 
title = "Ranking",
alphaLines = 0.3
) + scale_color_viridis(discrete=TRUE) + theme_ipsum()+ theme_void()

But I can`t make it look like this one:

enter image description here

Roman
  • 4,744
  • 2
  • 16
  • 58

1 Answers1

0

If I understand correctly what you mean with "symmetrical": You won't be able to reproduce a graph like this if the Rankings in the two columns don't match. In Ranking1 you have c(1:10), in Ranking2 you have c(1:7, 9, 11, 16).

Here's a minimal example to get closer to your goal:

Data

# Data with corrected rankings (1:10)
data <- read.table(text="
Group    Ranking1    Ranking2     Pop
  a           1            1      12345
  b           2            4      127868
  c           3            2      123477
  d           4            3      9485
  e           5            7      132588
  f           6            5      38741
  g           7            9      8372
  h           8            8     53423
  i           9            6      238419
  j           10           10     31314
           
           ", header = TRUE)

Code

# Build plot
GGally::ggparcoord(data,
                   columns = 2:3, groupColumn = 1,  
                   scale="globalminmax", 
                   showPoints = TRUE, 
                   title = "Ranking"
) + 
    # Reversed y axis with custom breaks to recreate 1:10 rankings
    scale_y_reverse(breaks = 1:10)

enter image description here

Edit: Making it pretty

If you want to add some pizzaz (as you were trying to do) you can do the following (no need to use theme_void()):

GGally::ggparcoord(data,
                   columns = 2:3, groupColumn = 1,  
                   scale="globalminmax", 
                   showPoints = TRUE, 
                   title = "Ranking"
) + 
    # Reverses scale, adds pretty breaks
    scale_y_reverse(breaks = 1:10) + 
    # Prettifies typography etc.
    hrbrthemes::theme_ipsum() + 
    # Removes gridlines
    theme(
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank()
    ) + 
    # Removes axis labels
    labs(
        y = element_blank(), 
        x = element_blank()
    )

enter image description here

Roman
  • 4,744
  • 2
  • 16
  • 58