问题
So I have a dataset with 5 rows and 20 columns.
I am trying to plot a hist3D from the plot3D package.
dt = structure(c(1, 1, 1, 3, 1, 2, 1, 0, 2, 1, 2, 1, 0, 1, 1, 0, 1,
0, 2, 2, 1, 1, 1, 1, 4, 4, 1, 1, 2, 3, 8, 1, 1, 2, 1, 10, 0,
1, 2, 1, 9, 0, 2, 4, 0, 4, 0, 5, 2, 2, 2, 0, 1, 2, 4, 1, 1, 3,
2, 6, 8, 1, 2, 2, 4, 10, 0, 2, 2, 4, 7, 0, 7, 1, 4, 11, 0, 4,
1, 2, 15, 0, 4, 2, 3, 16, 2, 7, 2, 2, 18, 3, 9, 0, 1, 15, 0,
15, 0, 2), .Dim = c(5L, 20L), .Dimnames = list(c("f Housework",
"g Odd jobs", "h Eating", "i Child care", "j Care for others"
), c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10",
"V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18", "V19",
"V20")))
The histogram
hist3D(x = 1:5, z = dt, scale = T, col = jet.col(100, alpha = 0.3), add = F, colkey = F, ticktype = "detailed")
What I would like is to
replace the
x-axis(1:5) by the row.names ("f Housework", "g Odd jobs", "h Eating", "i Child care", "j Care for others")Instead of having the same colours for each
xvariables, the rows of my data, (1:5,"f Housework", "g Odd jobs", "h Eating", "i Child care", "j Care for others"), I would like to have for each rows a different colour (if possible a different "heat-map" sequence colours).
What I would like is something like this (manual draw I know) :
Any advice ?
回答1:
I think I have a solution for the colors:
m <- matrix(rep(seq(5),each=20), ncol=20, nrow=5, byrow = TRUE)
hist3D(x = 1:5, z = dt, scale = T, col = jet.col(5, alpha = 0.3), add = F, colvar = m, colkey = T, ticktype = "detailed")
I will update the post as soon as I find out how to modify the x-axis labels.
回答2:
In case you haven't figured it out yet (or for the next person who comes along with a similar issue), there is a terrific blog post here about altering all axes things in hist3D: http://entrenchant.blogspot.co.uk/2014_03_01_archive.html
来源:https://stackoverflow.com/questions/31246789/r-hist3d-of-sequence-colour-and-label-issues