Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to plot my tibble in r like shown below?

My tibble looks like this:

# A tibble: 5 × 6
  clusters neuroticism introverty empathic    open unconscious
     <int>       <dbl>      <dbl>    <dbl>   <dbl>       <dbl>
1        1      0.242       1.02     0.511  0.327      -0.569 
2        2     -0.285      -0.257   -1.36   0.723      -0.994 
3        3      0.904      -0.973    0.317  0.0622     -0.0249
4        4     -0.836       0.366    0.519  0.269       1.00  
5        5      0.0602     -0.493   -1.03  -1.53       -0.168 

I was wondering how I can plot this with ggplot2, so that It looks like the big five personality profiles shown in this picture:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My goal is to plot an personality profile for each cluster.

Thanks in advance!

>Solution :

In order to plot it you’d typically need to have the data in a long format. A tidyverse-solution using pivot_longer and then ggplot could look like:

df |>
  pivot_longer(-clusters) |>
  ggplot(aes(x = name,
             y = value,
             fill = as.factor(clusters))) +
  geom_col(position = "dodge")

Plot:

enter image description here

Data:

df <-
  tribble(
  ~clusters,~neuroticism,~introverty,~empathic,~open,~unconscious,
  1,0.242,1.02,0.511,0.327,-0.569,
  2,-0.285,-0.257,-1.36,0.723,-0.994,
  3,0.904,-0.973,0.317,0.0622,-0.0249,
  4,-0.836,0.366,0.519,0.269,1.00,
  5,0.0602,-0.493,-1.03,-1.53,-0.168
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading