Home > Enterprise >  How to place count data right above the x-axis
How to place count data right above the x-axis

Time:07-13

I have a picture from a previous manuscript that I'm trying to recreate. They have the count data of each Edat right above the x-axis and it's tilted on it's side. Would someone be able to figure out how they did that?

Here is my data set:

> dput(head(ALLCLUTCHSIZEEGG, n=100))
structure(list(PVC = c("5011583", "6008934", "6013894", "6021051", 
"6021172", "6021627", "FNY", "6007961", "6014959", "HWF", "6013925", 
"HUW", "6070852", "6014326", "6014535", "6070862", "6008710", 
"6008806", "6013176", "6013198", "601321_", "6013766", "6013907", 
"601404_", "6014829", "6019049", "6020617", "6021296", "6034421", 
"20F", "226", "22W", "24V", "259", "27X", "28F", "28R", "28W", 
"29R", "2A7", "2AV", "2BY", "2CS", "2D3", "2HZ", "2LB", "37V", 
"6,005,684", "6,014,837", "A3J", "A3U", "A4N", "A9T", "ACX", 
"AFY", "AH6", "AHZ", "AL0", "ANB", "AP8", "ARA", "AS4", "AW5", 
"AYW", "B1A", "B2R", "B3S", "B3V", "B5F", "B7L", "B9A", "BDZ", 
"BHD", "BHX", "BJN", "BMU", "BPU", "BSP", "BTL", "BX4", "BXT", 
"BY0", "F1X", "FCF", "FDH", "FFR", "FL8", "FSR", "FSX", "FU5", 
"FVL", "FW2", "H06", "H94", "HA0", "HJ4", "HNU", "HPL", "HR5", 
"HRF"), Year = c(1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 
1995L, 1995L, 1995L, 1996L, 1996L, 1997L, 1998L, 1998L, 1998L, 
1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 
1999L, 1999L, 1999L, 1999L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 
2001L, 2001L, 2001L), totalV = c(131.6018329, 171.5553046, 121.6331389, 
188.4186198, 164.342858, 116.9765837, 171.0918454, 162.182944, 
182.037243, 182.2474643, 182.0570588, 189.3584683, 167.5214486, 
105.667161, 180.4278434, 118.4299258, 114.9047203, 117.5233062, 
183.2237556, 64.84888743, 67.34476853, 179.8050561, 196.9736654, 
116.5322925, 118.1339155, 116.2714585, 164.3279822, 170.9678674, 
174.0163013, 58.93118052, 102.4863282, 172.7867373, 108.5285789, 
113.1364641, 117.747205, 172.4886844, 122.3467623, 104.3666827, 
60.19094586, 107.8726138, 106.9625831, 65.98629816, 113.7929149, 
110.8721442, 115.9880061, 185.0896959, 111.5857755, 171.1446891, 
66.40863935, 119.1873412, 167.0677423, 199.6294104, 116.7911294, 
175.1773047, 181.1885253, 190.807993, 112.2536346, 61.03102835, 
189.4607803, 115.0591397, 181.2255581, 157.6421083, 173.6484269, 
200.9946072, 164.8496053, 188.773295, 121.0337775, 174.80985, 
171.8879165, 116.7466473, 188.2338073, 178.272079, 178.9604313, 
184.9853068, 164.163862, 113.1418614, 167.2918688, 175.2458489, 
128.5070682, 186.2197399, 122.2704427, 106.3206962, 118.9550288, 
121.7254435, 177.9666975, 174.7392697, 176.4316024, 186.9669759, 
188.7843782, 111.603327, 167.3893454, 110.0876149, 168.5546705, 
106.7025234, 173.9917622, 117.2408514, 181.380381, 188.6087943, 
177.7553861, 175.9251331), averageV = c(65.80091644, 57.18510154, 
60.81656944, 62.8062066, 54.78095265, 58.48829186, 57.03061512, 
54.06098134, 60.67908101, 60.74915477, 60.68568627, 63.11948942, 
55.84048285, 52.83358048, 60.14261445, 59.21496291, 57.45236013, 
58.76165312, 61.0745852, 64.84888743, 67.34476853, 59.9350187, 
65.65788848, 58.26614623, 59.06695775, 58.13572923, 54.77599407, 
56.98928912, 58.00543377, 58.93118052, 51.24316411, 57.59557909, 
54.26428947, 56.56823203, 58.87360248, 57.49622815, 61.17338114, 
52.18334137, 60.19094586, 53.9363069, 53.48129157, 65.98629816, 
56.89645744, 55.4360721, 57.99400307, 61.69656531, 55.79288776, 
57.04822969, 66.40863935, 59.59367062, 55.68924743, 66.54313679, 
58.39556471, 58.39243489, 60.3961751, 63.60266434, 56.12681732, 
61.03102835, 63.15359342, 57.52956987, 60.40851937, 52.54736944, 
57.88280897, 66.99820241, 54.94986844, 62.92443167, 60.51688874, 
58.26995, 57.29597215, 58.37332364, 62.74460242, 59.42402632, 
59.65347709, 61.66176894, 54.72128732, 56.57093068, 55.76395625, 
58.41528298, 64.2535341, 62.07324662, 61.13522137, 53.16034811, 
59.47751438, 60.86272173, 59.32223251, 58.24642324, 58.81053412, 
62.32232529, 62.92812605, 55.80166352, 55.79644846, 55.04380747, 
56.18489015, 53.35126172, 57.99725406, 58.62042568, 60.46012698, 
62.8695981, 59.25179536, 58.64171103), Clutch = c(2L, 3L, 2L, 
3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 3L, 
1L, 1L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 2L, 2L, 
3L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 
3L, 2L, 3L, 3L, 3L, 2L, 1L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 
3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 
3L), Edat = c(4L, 9L, 7L, 7L, 6L, 7L, 3L, 10L, 8L, 6L, 9L, 7L, 
6L, 12L, 12L, 7L, 14L, 14L, 13L, 13L, 13L, 12L, 12L, 13L, 13L, 
12L, 12L, 9L, 9L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 3L, 4L, 4L, 4L, 4L, 3L, 16L, 15L, 9L, 9L, 11L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 11L, 11L, 11L, 9L, 9L, 13L, 13L, 13L, 
13L, 9L, 13L, 13L, 13L, 13L, 13L, 13L, 9L, 13L, 9L, 9L, 13L, 
13L, 13L, 13L, 13L, 13L, 9L, 9L, 10L, 10L, 12L, 12L, 9L, 12L, 
10L, 12L, 10L, 9L, 10L, 9L, 9L)), row.names = c(NA, 100L), class = "data.frame")

Here is what my current graph looks like but obviously using the full data set :

ggplot(ALLCLUTCHSIZEEGG, aes(x = Edat, y = Clutch))  
    coord_cartesian(ylim = c(1, 3))  
    stat_summary(fun=mean, geom= "point", size = 2.5)  
    stat_summary(fun.data = mean_cl_normal,  
                 geom = "errorbar")   
    scale_x_continuous(breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28))  
    theme_classic()

enter image description here

Here is what I want the count data to look like:

enter image description here

I know the scale is different but that is fine. I just want the numbers at the bottom to be the same style.

Thank you for your help!

CodePudding user response:

You can use another stat_summary layer to calculate the number of points and then plot that data with a geom_text layer. For example

ggplot(ALLCLUTCHSIZEEGG, aes(x = Edat, y = Clutch))  
  coord_cartesian(ylim = c(1, 3))  
  stat_summary(fun=mean, geom= "point", size = 2.5)  
  stat_summary(fun.data= function(x) {
    data.frame(label=length(x), y=1)
  }, geom= "text", angle = 90, hjust=0)   
  stat_summary(fun.data = mean_cl_normal,  
               geom = "errorbar")   
  scale_x_continuous(breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28))  
  theme_classic()

The y value is hard coded at 1 but you can change that if necessary enter image description here

  •  Tags:  
  • r
  • Related