Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I make such graph in R - bar chart embedded in pie chart

I have following data:

    I   II  Total 
A   15  25  40
B   5   45  50
C   15  5   20

R data input:

group <- c("A", "B", "C", "A", "B", "C")
subgroup <- c("I", "I", "I", "II", "II", "II")
yvar <- c(15, 5, 15, 25, 45, 5)

As I was thinking a better way to present it, I came to idea of pie chart (preferably 3D) combined with bar chart (preferably 3D). Here is my rough sketch of my idea where bar chart is embedded into pie chart. Please suggest me if you have any other innovative idea to present such data.

enter image description hereenter image description here

like image 361
SHRram Avatar asked Nov 28 '22 18:11

SHRram


2 Answers

I cannot recommend strongly enough that you read some of Edward Tufte's literature on graphs and the display of quantitative data. Pie charts are close to the worst possible way to impart information to the user. Use of "3-D" images (e.g. bars) in charts is considered puerile at best -- it does nothing to improved readability or information flow.

So let me ask: what information (and what conclusions) are you trying to give to your reader? Why would you want to present the same information twice?

like image 60
Carl Witthoft Avatar answered Dec 04 '22 12:12

Carl Witthoft


Please suggest me if you have any other innovative idea to present such data

I don't have an innovative idea, but I do have what I think is a better way.

Think about your data. It's divided into groups (A, B, C), each of which also has a subgroup (I, II). So when you plot the data, you need 2 "visual aids": one of which illustrates the main groups and a second showing the subgroups.

A sensible way to do this is to separate the main groups by position and indicate the subgroups by colour.

So, you can reshape your data into a data frame (df1) which looks like this:

  group subgroup yvar
1     A        I   15
2     B        I    5
3     C        I   15
4     A       II   25
5     B       II   45
6     C       II    5

And then use ggplot to generate a stacked bar plot:

library(ggplot)
ggplot(df1, aes(x = group, y = yvar, fill = subgroup)) + geom_bar()

Result:

enter image description here

Note that ggplot calculates the totals for you. Look at that, look at your combined 3D bar + pie charts and ask yourself: which one best conveys the key features of the data, at a glance?

Please trust me and the data visualization experts on this forum when we tell you: what matters is clear presentation, not "what business people want."

like image 34
neilfws Avatar answered Dec 04 '22 13:12

neilfws