4

This is my data.frame,

> head(dat)
  word value number         name
1   10 0.001     30 gi|378283288
2   15 0.001     17 gi|378283288
3   20 0.001     16 gi|378283288
4   25 0.001     14 gi|378283288
5   30 0.001     12 gi|378283288
6   10 0.010     38 gi|378283288

> tail(dat)
    word value number         name
120   30   0.5     27 gi|378285158
121   10   1.0     34 gi|378285158
122   15   1.0     31 gi|378285158
123   20   1.0     27 gi|378285158
124   25   1.0     27 gi|378285158
125   30   1.0     27 gi|378285158

I want to present it in a bar graph. I explored the options, but not succeeded yet, because I want to present all the four columns. value can be used as X-axis, word can be used as y-axis and the name can be used as Z-axis. Then how to use number here?
May be a graph like this will be helpful, I can represent number by using color scale in legend.
example Now, my question is, how to generate this plot in R? and is it a right way to present my data?

ramesh
  • 1,187
  • 7
  • 19
  • 42
  • 2
    might want to check out the package `VRMLGen` (http://ico2s.org/software/vrmlgen.html) – Marc in the box Apr 24 '14 at 07:23
  • 3
    Personally, I find 3-d bar plots confusing. I would use a faceted regular bar plot instead. E.g. `ggplot(mtcars, aes(factor(cyl), fill=factor(am))) + geom_bar() + facet_grid(am~vs)` – shadow Apr 24 '14 at 07:31
  • 1
    @shadow: I agree, it takes time to understand the 3-D plot. But, 3-D plots are very suitable for comparison. In above one, Hong Kong and Beijing is easily comparable than faceted ggplot. – ramesh Apr 24 '14 at 07:36
  • 2
    There's a pretty good reason why these are discouraged by visual designers: they are really difficult to read. For example, what is the value for Sulfamethazine in Hangzhou? Realistically only the back row can be interpreted and given the perspective rotation even that is difficult. – Thomas Apr 24 '14 at 07:48
  • To add to the chorus, what you've got in that example is TMI (too much information). What's more important, e.g., chemical usage by type or by city? Or total (rather than by type) chemical usage, etc? Think about the message you want your audience to receive. – Carl Witthoft Apr 24 '14 at 11:27
  • Maybe you can build on this example https://stackoverflow.com/a/26822348/6136776 – eod May 19 '22 at 21:43

2 Answers2

2

I would do something like this:

library(ggplot2)
theme_set(theme_bw())
theme_update(strip.background=element_rect(colour="white"))

cities <- c("Beijing", "Hong Kong", "Macau", "Nanjing")
measures <- sprintf("Particle %s", toupper(letters[1:8]))
df <- data.frame(expand.grid(city=cities, measure=measures))
df$value <- rexp(nrow(df))

p <- (ggplot(df, aes(x=measure, y=value, color=measure, group=city)) +
      scale_color_discrete(guide=FALSE) +
      geom_point() + facet_wrap(~ city) +
      geom_line(color="grey", alpha=0.5) +
      xlab(""))
p

...which isn't so different from what shadow suggested in the comments.

I'm giving my (subjective) answer to your last question, "is [a 3D barplot a good] way to present my data." I'd prefer a faceted 2D plot to something 3D.

Adrian
  • 3,138
  • 2
  • 28
  • 39
0

The first part of your question has already been answered here.

To address the second part of your question "Is this the right way to present my data":

There are usually better options (e.g. clustered column chart, line chart, or panel chart) , and you need to rotate the 3D image to get the most out of it.

Community
  • 1
  • 1
Stenemo
  • 611
  • 7
  • 13