Reputation: 401
I have this DF:
structure(list(variable = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30,
31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38,
39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46,
47, 47, 48, 48, 49, 49, 50, 50), effsize = c(`Cohen's d` = -0.0466053417705654,
`Cohen's d` = -0.0466053417705654, `Cohen's d` = -0.0405357971450496,
`Cohen's d` = -0.0405357971450496, `Cohen's d` = -0.11302964407263,
`Cohen's d` = -0.11302964407263, `Cohen's d` = -0.283894977286524,
`Cohen's d` = -0.283894977286524, `Cohen's d` = -0.449582482925253,
`Cohen's d` = -0.449582482925253, `Cohen's d` = -0.611919484378943,
`Cohen's d` = -0.611919484378943, `Cohen's d` = -0.627997721674124,
`Cohen's d` = -0.627997721674124, `Cohen's d` = -0.373185006710527,
`Cohen's d` = -0.373185006710527, `Cohen's d` = -0.335812398459886,
`Cohen's d` = -0.335812398459886, `Cohen's d` = 0.0168774123974859,
`Cohen's d` = 0.0168774123974859, `Cohen's d` = 0.0393110863232343,
`Cohen's d` = 0.0393110863232343, `Cohen's d` = 0.220578802060183,
`Cohen's d` = 0.220578802060183, `Cohen's d` = 0.405462730832911,
`Cohen's d` = 0.405462730832911, `Cohen's d` = 0.261862219415595,
`Cohen's d` = 0.261862219415595, `Cohen's d` = -0.0455827253376345,
`Cohen's d` = -0.0455827253376345, `Cohen's d` = -0.123358008461568,
`Cohen's d` = -0.123358008461568, `Cohen's d` = -0.16283189663491,
`Cohen's d` = -0.16283189663491, `Cohen's d` = -0.329437941956624,
`Cohen's d` = -0.329437941956624, `Cohen's d` = -0.315505716699223,
`Cohen's d` = -0.315505716699223, `Cohen's d` = -0.294009801502364,
`Cohen's d` = -0.294009801502364, `Cohen's d` = -0.190389467175445,
`Cohen's d` = -0.190389467175445, `Cohen's d` = 0.00787129565840166,
`Cohen's d` = 0.00787129565840166, `Cohen's d` = -0.0309498666126677,
`Cohen's d` = -0.0309498666126677, `Cohen's d` = 0.142711349731605,
`Cohen's d` = 0.142711349731605, `Cohen's d` = 0.379764963685429,
`Cohen's d` = 0.379764963685429, `Cohen's d` = 0.633416184527805,
`Cohen's d` = 0.633416184527805, `Cohen's d` = 0.778103151771123,
`Cohen's d` = 0.778103151771123, `Cohen's d` = 0.759383017904672,
`Cohen's d` = 0.759383017904672, `Cohen's d` = 0.829555310181312,
`Cohen's d` = 0.829555310181312, `Cohen's d` = 0.729685426554946,
`Cohen's d` = 0.729685426554946, `Cohen's d` = 0.479843351968617,
`Cohen's d` = 0.479843351968617, `Cohen's d` = 0.386133371909261,
`Cohen's d` = 0.386133371909261, `Cohen's d` = 0.296743779912882,
`Cohen's d` = 0.296743779912882, `Cohen's d` = 0.215873869557711,
`Cohen's d` = 0.215873869557711, `Cohen's d` = 0.0650680645207325,
`Cohen's d` = 0.0650680645207325, `Cohen's d` = 0.153075154611332,
`Cohen's d` = 0.153075154611332, `Cohen's d` = 0.307499744562457,
`Cohen's d` = 0.307499744562457, `Cohen's d` = 0.363058841736803,
`Cohen's d` = 0.363058841736803, `Cohen's d` = 0.506252252552804,
`Cohen's d` = 0.506252252552804, `Cohen's d` = 0.258996876575378,
`Cohen's d` = 0.258996876575378, `Cohen's d` = 0.253088376818927,
`Cohen's d` = 0.253088376818927, `Cohen's d` = 0.51700810196539,
`Cohen's d` = 0.51700810196539, `Cohen's d` = 0.437850520002354,
`Cohen's d` = 0.437850520002354, `Cohen's d` = 0.498678285543434,
`Cohen's d` = 0.498678285543434, `Cohen's d` = 0.566471375050426,
`Cohen's d` = 0.566471375050426, `Cohen's d` = 0.494272030258101,
`Cohen's d` = 0.494272030258101, `Cohen's d` = 0.499249564696907,
`Cohen's d` = 0.499249564696907, `Cohen's d` = 0.377039108158137,
`Cohen's d` = 0.377039108158137, `Cohen's d` = 0.124434656376462,
`Cohen's d` = 0.124434656376462, `Cohen's d` = -0.203495362918663,
`Cohen's d` = -0.203495362918663), AgeGroup = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L,
2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 2L), .Label = c("Young", "Old"), class = "factor"), FA = c(0.714518666666667,
0.723876630952381, 0.728961368421053, 0.735228897233202, 0.701283807017544,
0.71396457312253, 0.68923661660079, 0.663229964912281, 0.613014666666667,
0.652671079051383, 0.547104, 0.602951166007905, 0.504106245614035,
0.558832648221344, 0.515752438735178, 0.487034052631579, 0.451825245614035,
0.476300007905138, 0.442370175438596, 0.441173656126482, 0.438668315789474,
0.435859173913043, 0.434047494071146, 0.450059526315789, 0.450561841897233,
0.478947649122807, 0.481134438596491, 0.461228027667984, 0.446763543859649,
0.451031316205534, 0.396206754385965, 0.406836889328063, 0.368716249011858,
0.357049368421053, 0.343943631578947, 0.368048932806324, 0.376060403508772,
0.398834193675889, 0.413613877192982, 0.434683889328063, 0.448746023715415,
0.434964894736842, 0.451208631578947, 0.450663276679842, 0.470569192982456,
0.473143399209486, 0.515300736842105, 0.502499193675889, 0.507495533596838,
0.543379719298246, 0.498506288537549, 0.550050701754386, 0.541725807017544,
0.482379664031621, 0.517293315789474, 0.458068636363636, 0.485205245614035,
0.423109671936759, 0.385925747035573, 0.438844403508772, 0.39522349122807,
0.362403612648221, 0.374209192982456, 0.350889750988142, 0.354036315789474,
0.336213118577075, 0.327800648221344, 0.340668122807018, 0.326388666666667,
0.322577146245059, 0.328114842105263, 0.319440624505929, 0.342721666666667,
0.323974818181818, 0.335501339920949, 0.357620473684211, 0.343831292490119,
0.372856842105263, 0.377362315789474, 0.361571442687747, 0.393890736842105,
0.377489727272727, 0.419330684210526, 0.38274228458498, 0.387899881422925,
0.419797666666667, 0.423127684210526, 0.385955055335968, 0.42140750877193,
0.377730351778656, 0.403711631578947, 0.366319122529644, 0.355189754940711,
0.390753140350877, 0.373226596491228, 0.347452173913044, 0.348689877192982,
0.340376324110672, 0.329466947368421, 0.344867375494071), p.adj = c(0.83,
0.83, 0.842553191489362, 0.842553191489362, 0.55, 0.55, 0.1105,
0.1105, 0.0055625, 0.0055625, 0.00115, 0.00115, 0.00100833333333333,
0.00100833333333333, 0.05, 0.05, 0.0504166666666667, 0.0504166666666667,
0.925510204081633, 0.925510204081633, 0.842553191489362, 0.842553191489362,
0.214705882352941, 0.214705882352941, 0.0176052631578947, 0.0176052631578947,
0.108571428571429, 0.108571428571429, 0.83, 0.83, 0.530487804878049,
0.530487804878049, 0.380263157894737, 0.380263157894737, 0.0347619047619048,
0.0347619047619048, 0.0506, 0.0506, 0.108571428571429, 0.108571428571429,
0.308333333333333, 0.308333333333333, 0.951, 0.951, 0.842708333333333,
0.842708333333333, 0.380263157894737, 0.380263157894737, 0.0112058823529412,
0.0112058823529412, 0.000206, 0.000206, 1.47666666666667e-05,
1.47666666666667e-05, 3.675e-08, 3.675e-08, 2.38e-07, 2.38e-07,
1.9875e-05, 1.9875e-05, 0.00192083333333333, 0.00192083333333333,
0.0120833333333333, 0.0120833333333333, 0.06, 0.06, 0.22, 0.22,
0.782558139534884, 0.782558139534884, 0.424358974358974, 0.424358974358974,
0.1105, 0.1105, 0.0359090909090909, 0.0359090909090909, 0.0055625,
0.0055625, 0.137096774193548, 0.137096774193548, 0.1625, 0.1625,
0.00192083333333333, 0.00192083333333333, 0.00364285714285714,
0.00364285714285714, 0.00137777777777778, 0.00137777777777778,
0.00115, 0.00115, 0.00192083333333333, 0.00192083333333333, 0.00354615384615385,
0.00354615384615385, 0.019475, 0.019475, 0.47875, 0.47875, 0.168181818181818,
0.168181818181818), p.adj.signif = c("ns", "ns", "ns", "ns",
"ns", "ns", "ns", "ns", "**", "**", "**", "**", "**", "**", "*",
"*", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "*", "*",
"ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "*", "*", "ns",
"ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns", "ns",
"*", "*", "***", "***", "****", "****", "****", "****", "****",
"****", "****", "****", "**", "**", "*", "*", "ns", "ns", "ns",
"ns", "ns", "ns", "ns", "ns", "ns", "ns", "*", "*", "**", "**",
"ns", "ns", "ns", "ns", "**", "**", "**", "**", "**", "**", "**",
"**", "**", "**", "**", "**", "*", "*", "ns", "ns", "ns", "ns"
)), row.names = c(1L, 3L, 5L, 7L, 9L, 11L, 13L, 15L, 17L, 19L,
21L, 23L, 25L, 27L, 29L, 31L, 33L, 35L, 37L, 39L, 41L, 43L, 45L,
47L, 49L, 51L, 53L, 55L, 57L, 59L, 61L, 63L, 65L, 67L, 69L, 71L,
73L, 75L, 77L, 79L, 81L, 83L, 85L, 87L, 89L, 91L, 93L, 95L, 97L,
99L, 101L, 103L, 105L, 107L, 109L, 111L, 113L, 115L, 117L, 119L,
121L, 123L, 125L, 127L, 129L, 131L, 133L, 135L, 137L, 139L, 141L,
143L, 145L, 147L, 149L, 151L, 153L, 155L, 157L, 159L, 161L, 163L,
165L, 167L, 169L, 171L, 173L, 175L, 177L, 179L, 181L, 183L, 185L,
187L, 189L, 191L, 193L, 195L, 197L, 199L), class = "data.frame")
I am plotting it with:
colorshape <- c("*" ="seagreen3", "**" = "gold2", "***" = "cyan3","****" = "firebrick1","ns" = "gray50", "Young" = "thistle2", "Old" = "lightblue")
ggplot(data = DF, aes(x = variable, y = FA)) +
geom_line(aes(color = AgeGroup), size =2, alpha= 0.7) +
geom_point(aes(color = factor(p.adj.signif)), size =2) +
scale_color_manual(values = colorshape)+
xlab("Point Along Tract") +
ylab("y") +
labs(color ="Significant") +
theme_classic()
Since My p.adj.signif
values are the same between Young
and Old
I would like to display those geom_points
on only one of those lines for easier visualization. I cannot get this to work though.
I am thinking I will need to edit the DF to create a single row for p.adj.signif
but I was wondering if there is a quicker/cleaner option in ggplot that I am not aware of?
Upvotes: 0
Views: 210
Reputation: 125697
This could be achieved by passing a filtered dataset to geom_point
like so:
library(ggplot2)
colorshape <- c("*" ="seagreen3", "**" = "gold2", "***" = "cyan3","****" = "firebrick1","ns" = "gray50", "Young" = "thistle2", "Old" = "lightblue")
ggplot(data = DF, aes(x = variable, y = FA)) +
geom_line(aes(color = AgeGroup), size =2, alpha= 0.7) +
geom_point(data = subset(DF, DF$AgeGroup == "Old"), aes(color = factor(p.adj.signif)), size =2) +
scale_color_manual(values = colorshape)+
xlab("Point Along Tract") +
ylab("y") +
labs(color ="Significant") +
theme_classic()
Created on 2021-06-03 by the reprex package (v2.0.0)
Upvotes: 2