1

I have this data below called test1.melted. 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 this data without using scatterpie?

Data:

test1.melted<-structure(list(Wet_lab_dilution_A = 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"), 
    NA12878 = 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), NA12877 = 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), IBD = 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)), row.names = c(NA, 
-24L), .Names = c("Wet_lab_dilution_A", "TypeA", "NA12878", "NA12877", 
"IBD", "variableA", "valueA"), class = "data.frame")

code:

p<- ggplot() + geom_scatterpie(aes(x=valueA, y=IBD, group=TypeA), data=test1.melted,
                           cols=c("NA12878", "NA12877")) + coord_equal()+
          facet_grid(TypeA~variableA)
p
MAPK
  • 5,635
  • 4
  • 37
  • 88

1 Answers1

0

Do you have to use a pie chart? (And you might; there's nothing wrong with them.)

Cause something like this could illustrate literally every variable in the dataset:

library(ggplot2)

test1.melted$NA12877 <- as.factor(test1.melted$NA12877)
test1.melted$NA12878 <- as.factor(test1.melted$NA12878)

p <- ggplot(data = test1.melted, aes(x=valueA, y=IBD, group=TypeA))
p <- p + geom_point(aes(colour=NA12877, fill = NA12878), stroke=3, size = 3, shape = 21)
p <- p + geom_text(aes(label = Wet_lab_dilution_A), size = 2)
p + facet_grid(TypeA ~ variableA) + theme_minimal()

enter image description here

12b345b6b78
  • 995
  • 5
  • 16
  • Thanks, but pie chart would be easier to visualize the proportion of NA12878 and NA12877 pairs. Just like what my code does. I also don't want to use A,B,C,D....letters. – MAPK Oct 21 '18 at 22:00
  • I think your color doesn't make sense here. – MAPK Oct 21 '18 at 22:04
  • If you run my code, you will see that I want to show the distribution of NA12877 and NA12878 (like how much percent of NA12877 and how much of NA12878) in each point. Your plot doesn't show that. – MAPK Oct 21 '18 at 22:09
  • Yes, I just plotted the values as stroke and fill, not as proportions. I'm assuming you have already considered using `geom_text()` to inscribe text that represents the percentage of one of the groups, say, NA12878? – 12b345b6b78 Oct 21 '18 at 22:13
  • I want to avoid using letters. That is too harsh on visualization. – MAPK Oct 21 '18 at 22:15
  • Is it possible to use mix colours? For example, if NA12877 is 50 percent and NA12878 is 50 percent, show half and half two colors? But then that would need pie chart again. – MAPK Oct 21 '18 at 22:21
  • I think it seems like if we are to continue with the `geom_scatterpie()` approach, `coord_equal()` might be the culprit. `coord_cartesian()` seems to do what I think you're intending to do, but stretches the pie charts. Specifying ridiculous limits in `coord_equal()` preserves the shape of the pie charts, but basically plots them all on the sime line. – 12b345b6b78 Oct 21 '18 at 22:24
  • I saw similar problem here, but not sure how I can modify my data to work like this:https://stackoverflow.com/questions/43984614/rggplot2geom-points-how-to-swap-points-with-pie-charts – MAPK Oct 21 '18 at 22:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182236/discussion-between-mapk-and-12b345b6b78). – MAPK Oct 21 '18 at 22:26