I've got a data set of
Target_num <- c(40, 40, 40, 40, 40, 40, 120, 120, 120, 120, 120, 120, 160, 160, 160, 160, 160,160,160, 200, 200, 200, 200, 200, 200, 240, 240, 240, 240, 240)
BP <- c(1:30)
db_s_abs <- data.frame(Target_num,BP)
And I'm trying to show only the data set for Target_num==160 but with the x-axis marks still present for 40-320 by 40.
a <- db_s_abs %>%
filter(Type=="BP") %>%
filter(Target_num=="160")
#Factoring column
db_s_abs$Target_num <- factor(db_s_abs$Target_num, levels=c("40","80","120","160","200","240", "280", "320"))
#Plotting chart
p_optim_bp_abs <- ggplot(aes(x=Target_num, y=SBP_Delta), data=db_s_abs, color="black")+
geom_hline(yintercept=0, col='grey')+
geom_point(aes(x=a$Target_num), alpha=0.8, position=position_dodge(width=1), color="blue", data=a)+
geom_smooth(method="matt", formula=y~x, size=1.5, se=TRUE, alpha=0.5, aes(x=a$Target_num, y=a$SBP_Delta), data=a)+
stat_summary(geom='pointrange', fun.data="mean_cl_boot", position=position_dodge(width=1), size=0.6, data=a)+
theme_minimal()+
scale_x_discrete(name="AV Delay", breaks=seq(40,320,40))+
scale_y_continuous(name="Change in BP (mmHg)", breaks = seq(-10,10, 2.5))
p_optim_bp_abs
I've tried changing it to
scale_x_discrete(name="AV Delay", breaks=db_s_abs$Target_num)
and changing the filter to a, taking out the filter, changing the breaks to a factored vector, but in spite of having factored the vector, it either comes up out of order with the stat_summary lines for all the other Target_num or with just 160 on the x-axis with the data I want it to show.
Any ideas how I can get it to show 40, 120, 160, 200, 240, 280, 320 on the x-axis and only display data points for 160?
question from:
https://stackoverflow.com/questions/65865439/is-it-possible-to-have-x-axis-ticks-and-labels-for-no-data-points-in-ggplot-to-s