I am trying to manually add pvalues to this graph...:
nice plot before stat_pvalue_manual
...but I get this one whenever I try stat_pvalue_manual
plot with wrong x-axis after stat_pvalue_manual
Here the code:
# PLOT ----
class(dm2means$block)
pd <- position_dodge(width = 0.2) # move them .2 to the left and right
# for themes() to work, 'x = as.factor(block)' has to be defined inside aes
gbaseSEM <- ggplot(dm2means, aes(y=mean, colour=EC, x = as.factor(block))) +
geom_errorbar(aes(ymin=lowerSEM, ymax=upperSEM), width=.3, size= 0.8, position=pd) + # 'width' is the width of the error bar
geom_point(position=pd) # if 2 factors to group: facet_grid(block ~ group)
#MULTIPLE DATA FRAMES IN ONE PLOT: LINE ONLY IN TRAIN WITH THE SUBPLOT
# it represents all points ...
dm2means$num_block = as.numeric(as.factor(dm2means$block)) ##TO PLOT LINES, TURN INTO NUMBER...
sub_train = dm2means[ dm2means$block != "hab",] # ...AND EXTRACT SUBFRAME EXCLUDING FIRST POINT
gbaseSEM <- gbaseSEM %+% dm2means #updates it
# ...but only connect the subset
glineSEM = gbaseSEM + geom_line(data = sub_train, position=pd, size=1,
aes(x = num_block, y = mean, colour=EC))
# Change x-axis labels
time_levs = levels(factor(dm2means$block))
#FINAL PLOT
g_finalSEM = glineSEM + aes(x=num_block) +
scale_x_continuous(
breaks= 1:length(time_levs),
labels = time_levs) +
ggtitle("dm2 Intracerebral: %brady by blocks") + # if insert /n inside the title, it adds a skip of line
xlab("10trials blocks") + ylab("mean brady ± SEM") + theme_light() +
scale_color_manual(values=wes_palette(n=3, name="Darjeeling1")) +
theme(
title = element_text(color="#273746", size=15, face="bold.italic"),
plot.title = element_text(hjust=0.5),
axis.text.x = element_text(angle = 60, hjust = 1), text=element_text(color="black", size=22)) +
stat_pvalue_manual(
stat.dm2, step.group.by = "block",
tip.length = 0, step.increase = 1, y.position= 35)
As you can see, my plot is build upon two data_frames, one with the points and another one with less values for the line (since the first point is not connected). Perhaps it's conflicting with that...
question from:
https://stackoverflow.com/questions/66062108/problem-with-stat-pvalue-manual-in-line-graph-conflict-with-x-axis-from-plot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…