How to create scatter plot with small pie charts?
1
0
Entering edit mode
2.5 years ago

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
R • 1.3k views
ADD COMMENT
1
Entering edit mode
2.5 years ago
Vitis ★ 2.4k

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...

ADD COMMENT

Login before adding your answer.

Traffic: 2303 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6