0

I am quite new to R and more to plotting with it.

I have this example data in a dataframe.

head(dframe)
  maingroup subgroup   n
1        BR        A 315
2        MV        A 394
3       SAN        A 253
4        BR        B 230
5        MV        B 242
6       SAN        B 152

Now I want to visualize it:

  • maingroup on the z-axis
  • subgroup on the x-axis
  • n on the y-axis

Quick and dirty example. enter image description here

buhtz
  • 10,774
  • 18
  • 76
  • 149

1 Answers1

4

If this is for publication (static image), you can use scatterplot3d:

library(scatterplot3d)
DT <- data.frame(maingroup = letters[1:6], subgroup = letters[26:21], n = 1:6)
scatterplot3d(x = DT$maingroup, # x axis
              y = DT$subgroup,  # y axis
              z = DT$n,         # z axis
              x.ticklabs = levels(DT$maingroup),
              y.ticklabs = levels(DT$subgroup))

enter image description here

For something more interactive, you can use plotly:

library(plotly)

plot_ly(x = DT$maingroup, # x axis
        y = DT$subgroup,  # y axis
        z = DT$n,         # z axis
        type = "scatter3d")

enter image description here

Chris
  • 6,302
  • 1
  • 27
  • 54
  • This is awsome. This answer my simple question. But now some detailed question are up. I will open a new one here. – buhtz Aug 17 '16 at 06:33
  • [How to get correct ticklabs in a 3d-scatterplot in R?](http://stackoverflow.com/questions/38989793/how-to-get-correct-ticklabs-in-a-3d-scatterplot-in-r) and [How to draw multiple 2d-plots in a 3d-plot in R?](http://stackoverflow.com/questions/38990001/how-to-draw-multiple-2d-plots-in-a-3d-plot-in-r) – buhtz Aug 17 '16 at 07:02