I did linear regression analysis between the response variable(y) and
predictor variables in the surgical data set considering pindex as a confounding variable.
I aim to plot the response variable(y) against the experimentally determined values of the predictor variables and to this end, I am Successful. However, could not able to indicate the estimated regression and p-value in the ggplot2.
In the code below, trying to do the analysis and the plot.
It would be much appreciated if someone could show me how to indicate the estimated regression and p-values inside the ggplot2.
library(olsrr)
library(tidyverse)
library(reshape2)
data(surgical)
## Regression
pre1 <-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
model <- lm(y ~ pindex + get(j), data = surgical)
bmodel <- broom::tidy(model)
bmodel$term[3]<-j
bmodel<-bmodel[3,]
mod_dres<-rbind(mod_dres,bmodel)
}
mod_dres
## Matching the significant variables with the orginal data and reshaping
pre1.plot = melt(surgical[,-c(2)], id.vars='y') %>%
dplyr::filter(variable %in% mod_dres$term)
## plot the predictors varaibles
ggplot(pre1.plot) +
geom_jitter(aes(value,y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value,y, colour=variable),
method=lm, se=FALSE, colour="darkorange") +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
Thank you!
You can add the equation and p-value to the plot using the "stat_poly_eq" function from the ggpmisc package:
library(tidyverse)
library(olsrr)
library(reshape2)
library(ggpmisc)
data(surgical)
## Regression
pre1 <-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
model <- lm(y ~ pindex + get(j), data = surgical)
bmodel <- broom::tidy(model)
bmodel$term[3]<-j
bmodel<-bmodel[3,]
mod_dres<-rbind(mod_dres,bmodel)
}
mod_dres
## Matching the significant variables with the orginal data and reshaping
pre1.plot = melt(surgical[,-c(2)], id.vars='y') %>%
dplyr::filter(variable %in% mod_dres$term)
## plot the predictors varaibles
ggplot(pre1.plot) +
geom_jitter(aes(value, y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value, y, colour=variable),
formula = y ~ x, method="lm", se=FALSE,
colour="darkorange") +
stat_poly_eq(formula = y ~ x,
aes(x = value, y = y, label = paste(..eq.label..,
..p.value.label..,
sep = "~~~~")),
parse = TRUE) +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
Edit
And you can add other statistics, like the R^2 value:
ggplot(pre1.plot) +
geom_jitter(aes(value, y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value, y, colour=variable),
formula = y ~ x, method="lm", se=FALSE,
colour="darkorange") +
stat_poly_eq(formula = y ~ x,
aes(x = value, y = y, label = paste(..rr.label..,
..p.value.label..,
sep = "~~~~")),
parse = TRUE) +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
See the docs for other statistics that can be included, e.g. "adj.rr.label", "f.value.label" etc: https://rdrr.io/cran/ggpmisc/man/stat_poly_eq.html
Related
P-values can be added to ggplot2 figures using the function ggpubr::stat_compare_mean(). However I cannot get the text "p = " to show up in front of the p-values. There are examples of how to add "p = " in front of p-values on the help page for the function but they do not seem to work.
Example
library(ggplot2)
library(ggpubr)
library(dplyr)
data("Cars93")
# List of the comparisons I would like to make for which p-values will be derived
my_comparisons <- list(c("Front", "Rear"),
c("Front", "4WD"),
c("Rear", "4WD"))
# creates the figure with p-value but no label indicating the values are p-values
Cars93 %>%
mutate(DriveTrain = factor(DriveTrain, levels = c("Front","Rear","4WD"))) %>%
ggplot(aes(x = DriveTrain, y = Price)) +
stat_compare_means(paired = F,
comparisons = my_comparisons) +
geom_boxplot(outlier.colour="white", outlier.fill = "white", outlier.shape = 1, outlier.size = 0) +
geom_jitter(shape=1, position=position_jitter(0.2), color = "black", fill = "white", size = 2) +
theme_bw() +
theme(axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"),
axis.title = element_text(size = 16, color = "black"),
axis.title.x = element_text(vjust = -0.5),
panel.grid = element_blank(),
panel.background = element_blank())
following the example at the bottom of the ?stat_compare_means page suggests using aes(label = paste0("p = ", ..p.format..) which does not work.
?stat_compare_means
Cars93 %>%
mutate(DriveTrain = factor(DriveTrain, levels = c("Front","Rear","4WD"))) %>%
ggplot(aes(x = DriveTrain, y = Price)) +
stat_compare_means(paired = F,
comparisons = my_comparisons,
aes(label = paste0("p = ", ..p.format..))) +
geom_boxplot(outlier.colour="white", outlier.fill = "white", outlier.shape = 1, outlier.size = 0) +
geom_jitter(shape=1, position=position_jitter(0.2), color = "black", fill = "white", size = 2) +
theme_bw() +
theme(axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"),
axis.title = element_text(size = 16, color = "black"),
axis.title.x = element_text(vjust = -0.5),
panel.grid = element_blank(),
panel.background = element_blank())
If you look at the label argument on the ?stat_compare_means help page it says the allowed values include "p.signif" or "p.format" which made me think ..p.format.. was deprecated, so I tried adding in "p.format" which also did not work.
Cars93 %>%
mutate(DriveTrain = factor(DriveTrain, levels = c("Front","Rear","4WD"))) %>%
ggplot(aes(x = DriveTrain, y = Price)) +
stat_compare_means(paired = F,
comparisons = my_comparisons,
aes(label = paste0("p = ", "p.format"))) +
geom_boxplot(outlier.colour="white", outlier.fill = "white", outlier.shape = 1, outlier.size = 0) +
geom_jitter(shape=1, position=position_jitter(0.2), color = "black", fill = "white", size = 2) +
theme_bw() +
theme(axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"),
axis.title = element_text(size = 16, color = "black"),
axis.title.x = element_text(vjust = -0.5),
panel.grid = element_blank(),
panel.background = element_blank())
In the end I would like the p-values to be preceded by p = such that the labels would say p = 0.00031, p = 0.059, and p = 0.027.
When you use a list of comparisons, stat_compare_means defaults to using geom_signif from the ggsignif package, essentially acting as a glorified wrapper function. In so doing, you lose some of the formatting flexibility. Better in this case to use geom_signif directly:
library(ggsignif)
Cars93 %>%
mutate(DriveTrain = factor(DriveTrain, levels = c("Front","Rear","4WD"))) %>%
ggplot(aes(x = DriveTrain, y = Price)) +
geom_signif(y_position = c(55, 60, 65),
comparisons = my_comparisons,
map_signif_level = function(x) paste("p =", scales::pvalue(x))) +
geom_boxplot(outlier.colour="white", outlier.fill = "white",
outlier.shape = 1, outlier.size = 0) +
geom_jitter(shape=1, position=position_jitter(0.2),
color = "black", fill = "white", size = 2) +
theme_bw() +
theme(axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"),
axis.title = element_text(size = 16, color = "black"),
axis.title.x = element_text(vjust = -0.5),
panel.grid = element_blank(),
panel.background = element_blank())
I did linear regression analysis between the response variable(y) and
predictor variables in the surgical data set considering pindex as a confounding variable.
I aim to plot the response variable(y) against the experimentally determined values of the predictor variables and to this end, I am Successful. However, could not able to indicate the estimated regression and p-value in the ggplot2.
In the code below, trying to do the analysis and the plot.
It would be much appreciated if someone could show me how to indicate the estimated regression and p-values inside the ggplot2.
library(olsrr)
library(tidyverse)
library(reshape2)
data(surgical)
## Regression
pre1 <-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
model <- lm(y ~ pindex + get(j), data = surgical)
bmodel <- broom::tidy(model)
bmodel$term[3]<-j
bmodel<-bmodel[3,]
mod_dres<-rbind(mod_dres,bmodel)
}
mod_dres
## Matching the significant variables with the orginal data and reshaping
pre1.plot = melt(surgical[,-c(2)], id.vars='y') %>%
dplyr::filter(variable %in% mod_dres$term)
## plot the predictors varaibles
ggplot(pre1.plot) +
geom_jitter(aes(value,y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value,y, colour=variable),
method=lm, se=FALSE, colour="darkorange") +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
Thank you!
You can add the equation and p-value to the plot using the "stat_poly_eq" function from the ggpmisc package:
library(tidyverse)
library(olsrr)
library(reshape2)
library(ggpmisc)
data(surgical)
## Regression
pre1 <-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
model <- lm(y ~ pindex + get(j), data = surgical)
bmodel <- broom::tidy(model)
bmodel$term[3]<-j
bmodel<-bmodel[3,]
mod_dres<-rbind(mod_dres,bmodel)
}
mod_dres
## Matching the significant variables with the orginal data and reshaping
pre1.plot = melt(surgical[,-c(2)], id.vars='y') %>%
dplyr::filter(variable %in% mod_dres$term)
## plot the predictors varaibles
ggplot(pre1.plot) +
geom_jitter(aes(value, y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value, y, colour=variable),
formula = y ~ x, method="lm", se=FALSE,
colour="darkorange") +
stat_poly_eq(formula = y ~ x,
aes(x = value, y = y, label = paste(..eq.label..,
..p.value.label..,
sep = "~~~~")),
parse = TRUE) +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
Edit
And you can add other statistics, like the R^2 value:
ggplot(pre1.plot) +
geom_jitter(aes(value, y, colour=variable),
colour="darkorange", size = 3) +
geom_smooth(aes(value, y, colour=variable),
formula = y ~ x, method="lm", se=FALSE,
colour="darkorange") +
stat_poly_eq(formula = y ~ x,
aes(x = value, y = y, label = paste(..rr.label..,
..p.value.label..,
sep = "~~~~")),
parse = TRUE) +
theme_minimal() +
theme(axis.title = element_text(size = 16,face="bold", colour = "black"),
axis.text = element_text(size = 16,face="bold", colour = "black"),
axis.line = element_line(colour='black'),
axis.ticks = element_line(colour='black'),
plot.title = element_text(hjust = 0.5,size=18,face="bold"),
legend.position = "bottom",
legend.title = element_text(color = "Black", size = 9, face = "bold"),
legend.text=element_text(color = "Black", size = 9, face = "bold"),
strip.text.x = element_text(size = 16,face="bold", colour = "black")) +
labs(x = "value",title = " ") +
facet_wrap(~variable, scales="free_x",nrow = 2, ncol = 4) +
theme(panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = "white", colour = "black"),
legend.key = element_blank(),
legend.title = element_blank())
See the docs for other statistics that can be included, e.g. "adj.rr.label", "f.value.label" etc: https://rdrr.io/cran/ggpmisc/man/stat_poly_eq.html
I'm using ggplot to graph a forest plot. I have used facet labels to label groups (in example below Test1, Test2, Test3). Is there a way to slightly shift the actual position of the facet label/strip to the left (as indicated by the arrows in my picture below)?
I can shift the position of the text within the facet label but I think I have done that as much as possible. Thus, I think I need to shift the actual facet label (strip bar/rectangle) itself. Is this possible?
Would be very grateful if anyone could help me or point out a way to get a similar effect!
Please find reproducible code here:
library(dplyr)
library(ggplot2)
library(ggforce)
library(tidyverse)
# Reproducible dataset
df <- data.frame(outcome = c('outcome1', 'outcome1', 'outcome2','outcome2','outcome3','outcome3','outcome4','outcome4','outcome5','outcome5'),
type = c('Test1','Test1','Test2','Test2', 'Test3', 'Test3', 'Test3','Test3', 'Test3', 'Test3'),
Coef = c(0.10026935, 0.10026935, 0.13713358, 0.13713358,0.07753188,0.07753188,0.09193794,0.09193794,0.06170916,0.06170916),
CIr_low = c(0.070955475,0.070955475,0.108705781,0.108705781,0.052595474,0.052595474,0.056340327,0.056340327,0.036185918,0.036185918),
CIr_high = c(0.12958323,0.12958323,0.16556139,0.16556139,0.10246828,0.10246828,0.12753555,0.12753555,0.08723240,0.08723240),
model = c(1,2,1,2,1,2,1,2,1,2))
# Set type as factor
df <- df %>% mutate(type = fct_relevel(type, "Test1","Test2","Test3"))
# Plot with ggplot
ggplot(df, aes(x = outcome, y = Coef, ymin = CIr_low,ymax =CIr_high,fill = as.factor(type))) +
geom_errorbar(aes(x= outcome, ymin=CIr_low, ymax=CIr_high), width=0.2,cex=0.5)+
geom_point(shape = 18, size = 5)+
facet_grid(type ~ ., scales = "free", space = "free") +
geom_hline(yintercept = 0, linetype = 'dashed', col = 'black') +
scale_y_continuous(limits = c(-0.1, 0.25)) +
ggforce::facet_col(facets = type ~ ., scales = "free_y", space = "free", strip.position = "top")+
theme_bw()+
coord_flip() +
xlab('Group')+
ylab(expression("Standardized" ~ beta *" (95%CI)"))+
theme(line = element_line(colour = "black", size = 0.5),
plot.margin = margin(0.5, 0.5, 0.5, 0.5, unit = "cm"),
strip.background = element_rect(colour = "white", fill="white"),
strip.text = element_text(colour = "black",face="italic"),
strip.text.x = element_text(size = 12,angle = 0,hjust = 0,face="bold.italic", color="darkblue"),
legend.position ="none",
axis.line.x = element_line(colour = "black"),
axis.line.y = element_blank(),
panel.border= element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
panel.spacing = unit(2, "lines"),
axis.ticks = element_blank(),
axis.title.x = element_text(colour = "black"),
axis.title.y = element_blank(),
axis.text=element_text( color = "black")
)
You can try:
ggplot(df, aes(x = outcome, y = Coef, ymin = CIr_low,ymax =CIr_high,fill = as.factor(type))) +
geom_errorbar(aes(x= outcome, ymin=CIr_low, ymax=CIr_high), width=0.2,cex=0.5)+
geom_point(shape = 18, size = 5, show.legend = F)+
geom_hline(yintercept = 0, linetype = 'dashed', col = 'black') +
scale_y_continuous(expression("Standardized" ~ beta *" (95%CI)"),limits = c(-0.1, 0.25)) +
xlab("")+
coord_flip() +
facet_grid(type~., scales = "free", space = "free_y", switch = "y") +
theme_minimal() +
theme(strip.placement = "outside",
strip.text.y.left = element_text(angle = 0,vjust = 1,size=12))
Or use a cowplot approach with ggtitle
plots <- df %>%
split(.$type) %>%
map2(.,names(.), ~ggplot(.x, aes(x = outcome, y = Coef, ymin = CIr_low,ymax =CIr_high,fill = as.factor(type))) +
geom_errorbar(aes(x= outcome, ymin=CIr_low, ymax=CIr_high), width=0.2, size=0.5)+
geom_point(shape = 18, size = 5, show.legend = F)+
geom_hline(yintercept = 0, linetype = 'dashed', col = 'black') +
scale_y_continuous(limits = c(-0.1, 0.25))+
coord_flip() +
xlab('')+
ylab(expression("Standardized" ~ beta *" (95%CI)"))+
ggtitle(.y)+
theme_minimal(base_size = 12)+
theme( panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title.position = "plot"))
cowplot::plot_grid(plots$Test1 + theme(axis.title.x = element_blank(), axis.ticks.x = element_blank(), axis.text.x = element_blank()),
plots$Test2 + theme(axis.title.x = element_blank(), axis.ticks.x = element_blank(), axis.text.x = element_blank()),
plots$Test3, ncol = 1)
I want to plot a dataframe (stats) with the coefficient and error bars, and automatically write the p-values above each point.
stats <- data.frame(Coefficient = c(-0.07,-0.04,-0.15173266),
p_value = c(.0765210755,0.5176050652,0.0001309025),
conf_low = c(-.1544418,-0.1686583,-0.2294873),
conf_high = c(0.007812205,0.084939487,-0.073978033),
Test = c("TestA","TestB","TestC"))
I am trying to make a function to plot the p-values above each Coefficient point. (The coord_flip in the plot below may also be throwing me off.
give.pval <- function(y){
return(c(x = Coefficient, label = stats$p_value))
}
The following ggplot is exactly what I need, except for the stat_summary line which I am doing incorrectly
ggplot(stats, aes(x = Test, y = Coefficient)) +
geom_point(aes(size = 6)) +
geom_errorbar(aes(ymax = conf_high, ymin = conf_low)) +
geom_hline(yintercept=0, linetype="dashed") +
#stat_summary(fun.data = give.pval, geom = "text") +
theme_calc() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text.x = element_text(size = 12, vjust = 0.5), axis.title.x = element_text(size = 16),
axis.text.y = element_text(size = 12), axis.title.y = element_blank(),
legend.position = "none",
plot.title = element_text(hjust = 0.5, size = 24)) +
coord_flip() +
ylab("Coefficient")
I would like the have this plot but with the appropriate p-value above each of the three Coefficient points.
Thanks for any advice.
This could be achieved with a geom_text layer where you map p_value on the label aes and some additional nudging
library(ggplot2)
stats <- data.frame(Coefficient = c(-0.07,-0.04,-0.15173266),
p_value = c(.0765210755,0.5176050652,0.0001309025),
conf_low = c(-.1544418,-0.1686583,-0.2294873),
conf_high = c(0.007812205,0.084939487,-0.073978033),
Test = c("TestA","TestB","TestC"))
ggplot(stats, aes(x = Test, y = Coefficient)) +
geom_point(aes(size = 6)) +
geom_errorbar(aes(ymax = conf_high, ymin = conf_low)) +
geom_hline(yintercept=0, linetype="dashed") +
geom_text(aes(label = p_value), nudge_x = .2) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text.x = element_text(size = 12, vjust = 0.5), axis.title.x = element_text(size = 16),
axis.text.y = element_text(size = 12), axis.title.y = element_blank(),
legend.position = "none",
plot.title = element_text(hjust = 0.5, size = 24)) +
coord_flip() +
ylab("Coefficient")
I would like to set the color and the shape of my 2 indicators which has been plotted in in two layes. The scale_color_manual works however the scale_shape_manual is not working. By having or not having this line "scale_shape_manual"; the result is the same and shape "16" (filled circle) is picked up?
comp_graph_1 <- ggplot() +
layer( mapping = aes(x=log(FV), y= msd, colour = "Reference"), #factor(Dataset)
data = ref,
stat = "identity",
geom = "point",
position = "identity")+
layer(mapping = aes(x=log(FV), y= msd, colour = "Target"), # "red" "blue"
data = target, #data = target[Is_Phone == 0],
stat = "identity",
geom = "point",
position = "identity")+
theme(panel.background = element_rect(fill = 'white'),
panel.grid = element_line(colour = "grey90") , panel.ontop = FALSE)+
theme(legend.justification = c(0, 0), legend.position = "bottom",
legend.background = element_rect(), legend.title = element_blank(), legend.key = element_rect(fill = "white"),
legend.text = element_text(size = 9,colour = "#7F7F7F"), panel.border = element_blank(),
axis.line = element_line(color = "#7F7F7F"))+
theme(plot.title = element_text(size = 16, colour = "#7F7F7F"),
axis.title.x = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F"),
axis.title.y = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F")) +
ggtitle(paste0(x, " / ", y, " distribution ")) + xlab(paste0("log ", x)) + ylab(y) +
scale_color_manual(values = c("Reference" ="#FFC000","Target" = "#00AEEF")) +
scale_shape_manual(values = c("Reference" =17, "Target" = 4))
I think where you have colour = "Target" you need a shape statement as well
shape = "Target" and shape = "Reference" and it should work.