This line of code is not working. The problem is when I add this geom_text line that is meant to filter out certain points of the data and label them.
This is the code:
ggplot(data=bg_total_df, aes(x = bg_total_num, y = bg_total$bloodGlucose)) +
geom_text(data = subset(bg_total, bloodGlucose < 78), label = bg_total$bloodGlucose)+
geom_point(color = ifelse(bg_total$bloodGlucose < 78, "red", "blue"))
Error: Aesthetics must be either length 1 or the same as the data (16): x, y
The ggplot + geom_point
code work together just fine. It's when the geom_text code is added where I get this error.
I have been trying to fix this geom_text set of code so that the outliers of the graph (bloodGlucose
is less than 78 and greater than 271) will be red and labeled with their number amount. The code that I have written is my first attempt at doing this by starting with the values less than 78.
Here is the code to set up the df.
bg_total <- filter(csutrauma.data, bloodGlucose >= 0)
bg_total_num <- 1:328
bg_total_df <- data.frame(bg_total_num, bg_total$bloodGlucose)
bg_total$bloodGlucose (these are the filtered out blood glucose data) <- c(118.0, 72.0, 207.0, 107.0, 99.0, 106.0, 98.0, 89.0, 114.0, 98.0, 109.0, 114.0, 85.0, 138.0, 100.0, 118.0, 99.0, 104.0, 80.0, 105.0, 113.0, 89.0, 116.0, 121.0, 120.0, 109.0, 97.0, 100.0, 112.0, 133.0, 95.0, 107.0, 91.0, 133.0, 80.0, 114.0, 118.0, 109.0, 111.0, 115.0, 122.0, 90.0, 114.0, 93.0, 106.0, 555.0, 106.0, 106.0, 119.0, 95.0, 153.0, 118.0, 75.0, 112.0, 102.0, 103.0, 150.0, 109.0, 110.0, 206.0, 103.0, 266.0, 103.0, 104.0, 119.0, 106.0, 94.0, 94.0, 119.0, 120.0, 96.0, 252.0, 121.0, 126.0, 317.0, 170.0, 119.0, 98.0, 124.0, 137.0, 255.0, 136.0, 126.0, 0.0, 117.0, 134.0, 133.0, 102.0, 150.0, 232.0, 132.0, 112.0, 78.0, 155.0, 113.0, 122.0, 153.0, 96.0, 83.0, 154.0, 41.0, 91.0, 120.0, 134.0, 126.0, 168.0, 196.0, 125.0, 105.0, 105.0, 93.0, 88.0, 89.0, 93.0, 120.0, 93.0, 93.0, 135.0, 102.0, 86.0, 93.0, 141.0, 150.0, 96.0, 101.0, 61.0, 110.0, 81.0, 97.0, 140.0, 95.0, 106.0, 117.0, 119.0, 139.0, 110.0, 101.0, 128.0, 107.0, 160.0, 122.0, 135.0, 59.0, 102.0, 72.0, 145.0, 104.0, 134.0, 113.0, 105.0, 107.0, 100.0, 65.0, 100.0, 136.0, 110.0, 159.0, 107.0, 115.0, 101.0, 493.0, 78.0, 84.0, 229.0, 102.0, 172.0, 139.0, 102.0, 541.0, 94.0, 91.0, 88.0, 181.0, 129.0, 123.0, 108.0, 115.0, 97.0, 159.0, 124.0, 118.0, 138.0, 182.0, 115.0, 119.0, 101.0, 99.0, 88.0, 134.0, 104.0, 152.0, 130.0, 90.0, 100.0, 157.0, 112.0, 120.0, 110.0, 112.0, 104.0, 71.0, 120.0, 254.0, 118.0, 119.0, 94.0, 104.0, 183.0, 227.0, 210.0, 150.0, 93.0, 91.0, 99.0, 86.0, 90.0, 115.0, 247.0, 111.0, 109.0, 90.0, 113.0, 98.0, 80.0, 145.0, 101.0, 94.0, 94.0, 138.0, 241.0, 3.8, 106.0, 93.0, 96.0, 105.0, 181.0, 95.0, 82.0, 82.0, 18.0, 148.0, 175.0, 323.0, 118.0, 89.0, 100.0, 117.0, 175.0, 200.0, 147.0, 108.0, 210.0, 123.0, 136.0, 107.0, 117.0, 116.0, 154.0, 56.0, 102.0, 105.0, 100.0, 108.0, 226.0, 149.0, 86.0, 116.0, 140.0, 133.0, 121.0, 122.0, 98.0, 95.0, 118.0, 114.0, 113.0, 94.0, 70.0, 52.0, 110.0, 189.0, 82.0 200.0, 89.0, 95.0, 93.0, 111.0, 117.0, 110.0, 156.0, 87.0, 136.0, 336.0, 112.0, 128.0, 92.0, 61.0, 130.0, 119.0, 152.0, 90.0, 111.0, 116.0, 133.0, 94.0, 326.0, 121.0, 119.0 121.0 152.0, 113.0, 128.0, 123.0, 155.0, 176.0, 101.0, 248.0, 64.0, 90.0, 105.0, 235.0, 124.0, 142.0, 388.0, 118.0, 202.0, 156.0, 195.0)
Thank you in advance.