I need to put a 3D kind of graph similar to attached image created in excel. I am not sure whether we can do this in ggplot?
structure(list(Name = c("A", "B", "C", "D"), P = c(15089, NA,
NA, 43083), Q = c(1589, NA, NA, 18120), R = c(93751, NA, 4709,
211649), S = c(34167, 1323, 1520, 82378), T = c(8831, NA, 4544,
15157)), .Names = c("Name", "P", "Q", "R", "S", "T"), row.names = c(NA,
4L), class = "data.frame")
I have worked with this following code.
ggplot(a, aes(x = a$A, y = a$Amount, fill = a$B)) +
geom_col(position = 'stack') +
geom_text(aes(label = a$Amount), position = position_stack(vjust = .5),
color='grey25', size=2) + coord_flip()
The problem is the labels which shows on top the the graph is overlapping
Updated: Actually, I thought I need to reshape the data to achieve this kind of graph, not so sure though. So I reshaped the like below
structure(list(AA = c("A", "A", "A", "A", "A", "B", "B", "B",
"B", "B", "C", "C", "C", "C", "C", "D", "D", "D", "D", "D"),
BB = c("P", "Q", "R", "S", "T", "P", "Q", "R", "S", "T",
"P", "Q", "R", "S", "T", "P", "Q", "R", "S", "T"), Amount = c(15089,
1589, 93751, 34167, 8831, NA, NA, NA, 1323, NA, NA, NA, 4709,
1520, 4544, 43083, 18120, 211649, 82378, 15157)), .Names = c("AA",
"BB", "Amount"), row.names = c(NA, 20L), class = "data.frame")
I tried the following code to achieve this to which the labels are overlapping
ggplot(a, aes(x = AA, y = Amount, fill = BB)) +
geom_col(position = 'stack')+
geom_text(aes(label = Amount),
position = position_stack(vjust = 0.2),
color='grey25',
size=2) +
coord_flip()
Also, when I supply this to ggploty for shiny, the graph is not coming in dashboard