How to create scatter plot with small pie charts?
Hi All, I have been struggling to plot this data. I want to show the distribution of my samples within pie chart and then I want to show those pie charts as scattered geom_points. I also have the code to plot my data using package scatterpie, but due to inherent problem of scatterpie (if coordinates are not cartesian,i.e. equal horizontal and vertical distances), you would not get properly formatted plot. Is there a better way to plot pie charts for this data without using scatterpie in R?
test1.melted <- structure(list(sample = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L), .Label = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L"), class = "factor"), TypeA = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("I", "II"), class = "factor"),
NA78 = c(100L, 50L, 25L, 20L, 10L, 0L, 100L, 50L, 25L, 20L,
10L, 0L, 100L, 50L, 25L, 20L, 10L, 0L, 100L, 50L, 25L, 20L,
10L, 0L), NA77 = c(0L, 50L, 75L, 80L, 90L, 100L, 0L, 50L,
75L, 80L, 90L, 100L, 0L, 50L, 75L, 80L, 90L, 100L, 0L, 50L,
75L, 80L, 90L, 100L), ITS = c(1.02, 0.619, 0.294, 0.244,
0.134, 0.003, 0.003, 0.697, 0.964, 0.978, 1, 1, 1.02, 0.619,
0.294, 0.244, 0.134, 0.003, 0.003, 0.697, 0.964, 0.978, 1,
1), variableA = c("tEst", "tEst", "tEst", "tEst", "tEst",
"tEst", "tEst", "tEst", "tEst", "tEst", "tEst", "tEst", "pair",
"pair", "pair", "pair", "pair", "pair", "pair", "pair", "pair",
"pair", "pair", "pair"), valueA = c(0.1, 59.8, 84.6, 89.2,
97.4, 100, 99.6, 56.4, 29.9, 24, 12.1, 0.1, 0.1, 51.08, 75.28,
80.09, 90.16, 100, 100, 48.09, 23.97, 18.81, 9.24, 0.08)), .Names = c("sample",
"TypeA", "NA78", "NA77", "ITS", "variableA", "valueA"), row.names = c(NA,
-24L), class = "data.frame")
my code:
p<- ggplot() + geom_scatterpie(aes(x=valueA, y=ITS, group=TypeA), data=test1.melted,
cols=c("NA78", "NA77")) + coord_equal()+
facet_grid(TypeA~variableA)
p
• 2,775 views
•
link
1 answer
Please see this:
https://guangchuangyu.github.io/2016/12/scatterpie-for-plotting-pies-on-ggplot/
Seems you could play some tricks on the y-axis to make scatterpie work...
• 1 views
•
link
Log in to answer this question.