-1

I only have 3 observations but 36 variables. This is in fact an output of dplyr's group_by()+summarise(). Considering this as a category, I need to represent this data graphically in any possible way (scatterplot, line etc..).

Below is the data.

> data_cluster %>% 
+   group_by(PosGrp) %>%
+   summarise_all("mean",na.rm=TRUE)

 PosGrp `Weak Foot` `Skill Moves` Crossing Finishing HeadingAccuracy ShortPassing Volleys Dribbling
  <fct>        <dbl>         <dbl>    <dbl>     <dbl>           <dbl>        <dbl>   <dbl>     <dbl>
1 DEF           2.82          2.21     51.2      35.1            61.1         59.2    35.6      52.4
2 FWD           3.12          2.70     50.8      65.9            60.1         59.8    57.7      65.1
3 MID           3.10          2.72     58.5      54.3            52.1         67.0    50.8      65.4
Salih
  • 391
  • 1
  • 13
  • 2
    You should post some of your data as a [small reproducible example](https://stackoverflow.com/a/5963610/11810235). With that being said, you should convert your summarized data to long format using tidyr::gather or the newer tidyr::pivot_longer. This will let you easily plot all response values in ggplot2. – rpolicastro Jan 10 '20 at 10:57
  • I have actually shown the data. The table that you see is actually the data. It's a derived (grouped+summarised) data I should say. My aim is to plot this derived data. I have not heard about tidyr::gather, neither does any answers for similar questions points to it. Let me have look. Thank you ! – Salih Jan 10 '20 at 11:02
  • The data should be in a format that people can copy and paste into R, so that they can work with your data and give an answer using your data. I recommend reading the linked guide in my first comment. – rpolicastro Jan 10 '20 at 14:34

1 Answers1

0

It's not very clear what kind of plot you will like, but most the code below can get you started. You need to change it to long format for use in ggplot, then after that I would suggest a type of plot (below is bar plot) with facet_wrap around your variables:

data_cluster =  data.frame(
  PosGrp = sample(c("DEF","FWD","MID"),100,replace=TRUE),
  "Weak Foot"=runif(100),
  "Skill Moves"=rnorm(100),
  "Crossing Finishing" = rpois(100,80),
  "Crossing" = rpois(100,80)
)

data_cluster %>% 
group_by(PosGrp) %>%
summarise_all("mean",na.rm=TRUE) %>%
pivot_longer(-PosGrp) %>%
ggplot() + geom_col(aes(x=PosGrp,y=value,fill=PosGrp))+
  facet_wrap(~name,scale="free_y")
StupidWolf
  • 45,075
  • 17
  • 40
  • 72