buhtz
buhtz

Reputation: 12152

How do I visualize 3 column data in R with a 3-dimensional plot?

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:

Quick and dirty example. enter image description here

Upvotes: 0

Views: 900

Answers (1)

Chris
Chris

Reputation: 6362

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

Upvotes: 4

Related Questions