Nicola Gambaro
Nicola Gambaro

Reputation: 53

How can I make a graph like this in R?

I need to make a probability plot for a geochemical analysis (cumulative vs element concentration in log scale), like in the picture:

enter image description here.

I have tried with ppPlot in the 'qualityTools' package with the 'log-normal' argument but for some elements it does not work. It says I need positive values for a log-normal distributions but they are all positive, I've checked. I think the command uses the 'density' function in base R, and its density model inadvertently produces negative concentration values. The 'qqnorm' command in base R produces a different kind of plot.

How can I go around this?

Edit: Here's part of my magnesium data (I need to generate a similar graph with them):

    mg <- c(51.400, 149.000, 276.000, 135.000, 179.000,  81.000, 116.000,   8.150,   7.770,   7.870,   8.840,  15.600,  13.400,
  57.400,   7.440,  14.800,  40.800,  15.100,  21.400,   5.550,   3.390,  18.800,  20.100,  19.600,  11.600,  11.700,
  12.200,  12.500,  11.700,  12.100,  13.000,  12.300,  13.300,  13.200,  12.600,  29.700,  25.400,  21.000,  11.100,
  11.500,  11.000,  32.600,  17.500,  16.500,  18.100,  27.200,  21.200,  26.400,  18.800,  19.900,  32.000,  28.600,
  29.400,  30.700,   2.370,   2.070,   1.850,   1.970,  24.900,  19.100,  17.400,  23.100,  50.100,  48.800,  18.000,
   15.800,  27.100,  43.500,   4.820,  13.400,  14.600,  24.100,  22.700,  22.500,  43.500,  41.300,  43.700,  41.100,
    40.800,  63.700,   7.700,   8.360,  60.000,  58.400,  63.100,  65.100, 219.000,  25.800,   4.940,   3.670,  13.800,
   5.190,  14.700,  15.000,  13.100,  12.300,  10.700,  10.700,  11.100,  10.100,  10.600,  63.200,  19.800,  22.200,
  17.600,  11.500,  10.600,   9.380,   3.190,   9.180,  10.800, 189.000, 190.000, 152.000, 119.000, 194.000,  56.100)

Upvotes: 0

Views: 97

Answers (1)

SSD93
SSD93

Reputation: 39

This is my solution, but i had to create a new hole data frame with random numbers:

ggplot()+
  geom_point(data=N,aes(x=Prob,y=AS))+
  scale_x_log10(breaks=c(0.1,1,5,20,50,80,95,99,99.9))+
  scale_y_log10(expand=c(0,0),
breaks=c(seq(0.01,0.1,0.01),seq(0.2,1,0.1),seq(2,10,1)))+
  ylab(paste("As(","\U00B5","g/l)"))+ xlab("Cummulative probability (%)")+
 theme_bw()+annotation_logticks()

For the lines you should add segments and text in other layer for example. Ther is a lot to improve in this plot :)

Upvotes: 1

Related Questions