R scatterplot3d: a custom axis step and ticks -
greeting all.
i striving scatterplot3d
plot -- graphical representation of data.frame of 3 variables 1 of them response variable, have wrong representation of axis steps. here code ("temp" data.frame):
library(scatterplot3d) temp[,1] <- as.numeric(levels(temp[,1]))[temp[,1]] (m in temp[,2]) m <- as.factor(as.numeric(m)) (m in temp[,3]) m <- as.factor(as.numeric(m)) colnames(temp) = c("values", "factors", "antifactors") # "values" responce variable xtickmarks<-c("antifactor1","antifactor1", "antifactor3") ytickmarks<-c("factor1","factor2") plot3d <- scatterplot3d(temp[,3], temp[,2], temp[,1], color = "blue", pch = 19, type = "h", box = t, xaxt = "n", x.ticklabs=xtickmarks, y.ticklabs=ytickmarks, zlab = "time, min.") dput(temp) structure(list(values = c(395, 310, 235, 290, 240, 490, 270, 225, 430, 385, 170, 55, 295, 320, 270, 130, 300, 285, 130, 200, 225, 90, 205, 340, 3, 8, 1, 0, 0, 0, 3, 2, 5, 2, 3, 5, 2, 3, 200, 5, 5, 10, 5, 5, 5, 10, 10, 130, 5, 200, 80, 10, 360, 10, 5, 8, 30, 8, 10, 10, 10, 5, 240, 120, 3, 10, 25, 5, 5, 10, 190, 30, 115, 1, 1, 1, 2, 3, 5, 2, 5, 3, 3, 3, 2, 3, 2, 3, 0, 0, 195, 150, 2, 2, 0, 2, 1, 1, 2, 1, 2, 1, 1, 1, 3, 2, 2, 1, 2, 2, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1), factors = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("factor1", "factor2"), class = "factor"), antifactors = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l), .label = c("antifactor1", "antifactor2", "antifactor3"), class = "factor")), .names = c("values", "factors", "antifactors"), row.names = c(na, -120l), class = "data.frame")
here picture of plot got:
the trouble got twice more ticks @ x , y axis needed. intended have 1 set of factor1..2 , antifactor1..3 ticks @ each of x, y axis. if run scatterplot3d
without using x.ticklabs
option, gives "0, 0.5, 1, 1.5, 2.0, ...3.0" ticks etc @ axis. way set step in x, y axis strong integer "1", discrete ticks displayed in right place?
it seems scatterplot3d
coerces discrete explanatory variables 'factor' , 'antifactor' factor numeric. see e.g.:
levels(df$factors) # [1] "factor1" "factor2" unique(as.numeric(df$factors)) # [1] 1 2 levels(df$antifactors) # [1] "antifactor1" "antifactor2" "antifactor3" unique(as.numeric(df$antifactors)) # [1] 1 2 3
the labels have created recycled label @ each (default) tick mark. note typo in 'xtickmarks' - assume second 'antifactor1' should 'antifactor2'.
you may consider alternative ways visualize data, e.g. this:
library(ggplot2) ggplot(data = temp, aes(x = antifactors, y = values, fill = factors)) + geom_boxplot()
Comments
Post a Comment