Reputation: 437
I am doing a linear interpolation using ggplot2, with two series which generates a legend, reporting Primer A
and Primer B
.
On the legend appears a strange a
on the left of the symbol which I am not able to remove.
I saw another similar topic: "Remove 'a' from legend when using aesthetics and geom_text" but it is not the same case, in my case I am using geom_text_repel()
in that one somply geom_text()
.
What could be the problem?
library(ggplot2)
library(ggrepel)
# Dataframe creation
RawData <- data.frame(
Time_h = c(0, 10, 20, 30, 40, 50, 60, 0, 10, 20, 30, 40, 50, 60),
Percentage_Curing = c(100, 95.48, 91.35, 87.9, 84.77, 81.97, 79.37, 100, 92.15, 84.29, 76.65, 69.6, 63.42, 59.66),
Ref = c(
"Primer A", "Primer A", "Primer A", "Primer A", "Primer A", "Primer A",
"Primer A", "Primer B", "Primer B", "Primer B", "Primer B", "Primer B",
"Primer B", "Primer B"
)
)
print(data)
is.num <- sapply(RawData, is.numeric) ##Reduces decimal figures
RawData[is.num] <- lapply(RawData[is.num], round, 2)
#Force first point: (0;0)
RawData$weight = ifelse(RawData$`Time_h`==0, 100, 1)
library(tidyverse)
library(investr)
#Creation of the linear model
(rawdgrps <- RawData %>% group_by(Ref) %>% group_split())
models <- map(rawdgrps,
~nls(formula=`Percentage_Curing` ~ (a_ * `Time_h`) + b_,
start = list(a_ = 10, b_ = 5),
weights = weight,
data = .x)
)
(predictions <- map2_dfr(models,rawdgrps,
~bind_cols(.y, investr::predFit(.x, newdata = .y,
interval = "confidence", level = .8)
)))
### GRAPH CREATION
Graph <- ggplot(data=predictions, aes(x=`Time_h`, y=`Percentage_Curing`, col=Ref)) +
geom_point( shape = 1, size = 2.5) +
geom_line(aes(y=fit)) +
geom_ribbon(aes(ymin=lwr,ymax=upr),alpha=.1,linetype=0) +
scale_color_manual(values=c('#f92410','#644196')) +
labs(color='') +
theme(legend.justification = "top") +
geom_text_repel(max.overlaps = Inf,
segment.curvature = 0.1,
segment.ncp = 3,
segment.angle = 60,
force = 1,
size = 2.5,
angle = 0,
segment.alpha = 0.25,
segment.size = 0.25,
nudge_y = 0.0,
egment.square =FALSE,
min.segment.length = 0,
family = "Calibri",
box.padding = 1.5,
aes(label=paste0( "Weight ", `Percentage_Curing`, " %", "\n", "Time: ",`Time_h`, " min")),
size = 3,
hjust=0.1)
Graph
Upvotes: 0
Views: 47