0

I am looking for an elegant visualization of this mock dataset. My dataset a.dat is the in the form of a csv.

Category,Treatment,Score
Red,Compact,1
Red,Expand,1
Blue,Neutral,2
Blue,Destroy,1
Green,Compact,4
Green,Expand,3
Red,Expand,2
Yellow,Neutral,3
Red,Destroy,5
Blue,Compact,2
Red,Compact,1
Yellow,Expand,3
Yellow,Expand,2
Yellow,Expand,3
Blue,Neutral,5
Blue,Destroy,2
Red,Compact,1
Green,Neutral,2
Blue,Destroy,4
Blue,Compact,3
Red,Expand,5
Yellow,Expand,2
Yellow,Expand,1
Yellow,Neutral,3
Blue,Destroy,2
Blue,Compact,3
Red,Expand,5
Blue,Expand,2
Blue,Neutral,1
Green,Destroy,2
Green,Compact,4
Red,Neutral,1
Yellow,Destroy,2
Yellow,Compact,1

I want the Categories of Red, Blue, Green, Yellow, to flow into the Treatment. Each Treatment also has a stacked barplot for the score-counts, i.e: the number of times a particular score was registered for each Treatment. Below is a (badly) hand-drawn expectation:

Expected_image

Please try and make the solution as tidyverse friendly as possible.

Ginko-Mitten
  • 304
  • 1
  • 11
  • just to be clear, are you wanting the connecting lines in the sankey bit to be fat, like [these](https://i.stack.imgur.com/Sw7OR.jpg)? – Mark Jun 26 '23 at 00:28
  • the tricky part about your question is that, assuming you do indeed want a sankey diagram, the end labels (Compact, Expand, Neutral, Destroy) aren't going to be equal widths apart- some of the end "bits" are going to be fatter than others, as in the link from the previous comment. This means you have to somehow get the height of each label from the package which makes the sankey chart somehow. – Mark Jun 26 '23 at 01:30
  • @Mark: Yes! If I tried drawing that, my already ugly image would would even less presentable – Ginko-Mitten Jun 26 '23 at 05:33
  • I had a look at the documentation for the sankey diagram types listed [here](https://stackoverflow.com/questions/9968433/sankey-diagrams-in-r), and I couldn't see anything about getting the finishing positions of the labels at the end (which I think is the hardest part of what you're asking- the labels on the end have to line up with the bar chart). I couldn't see that in any of them sadly. The only thing I can think of is maybe there is some way of getting the positions of the labels of the end of the sankey diagram, and then passing those as positions for bars in the bar chart – Mark Jun 26 '23 at 06:04
  • @Mark: You are kind for trying. I looked at the documentation as well. Over an above all the problems around generating a simple Sankey, I was also having downstream issues of saving it as a pdf. I did not find the steps very reproducible. – Ginko-Mitten Jun 26 '23 at 09:39
  • no worries! I wish I could have been of more use. FWIW, (I don't know your situation) but I think the number of instances of the last column of values (i.e. the count I think you were graphing in the bar chart) is already represented by the number of lines going in to each value in that column, so a bar chart is a bit redundant – Mark Jun 26 '23 at 09:59
  • If you want to save a sankey, it depends on the package you are using, but if it's `ggalluvial`, then you can use `ggsave` – Mark Jun 26 '23 at 09:59

0 Answers0