0
I would like to leave the bar data label of graph "1" equal to graph 2, removing the background color from the label and coloring the numbers.
I’m using the argument geom_label
on both charts, but I’m not getting the modification.
Below is the command and a graphic illustrative figure.
library(ggplot2)
library(lubridate)
library(gridExtra)
library(ggpubr)
dt <- data.frame(periodo = c ("Maio", "Junho"),
peso = c(14.1, 14.51, 12.25, 12.81),
atr = c(140.61, 130.29, 131.5, 146.23))
dt$LOCAL <- rep(c("1", "5"), each = nrow(dt)/2)
dt$periodo <- factor(dt$periodo, levels = c("Maio", "Junho"))
g_col <- ggplot(dt, aes(x = periodo, y = peso, fill = LOCAL, label = rownames(dt))) +
geom_col(position = "dodge")+
theme_gray() +
geom_label(aes(label = peso), position = position_dodge(width = 1), fontface = "bold",vjust =
-0.1,show.legend = FALSE)+
scale_y_continuous(limits = c(0,25))+
labs(x = "Período", y = "", title = "", subtitle = "Evolução peso")+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x=element_text(face = "bold", size = 10, colour = "black"),
plot.subtitle = element_text(size = 12, face = "bold"))+
scale_fill_manual(values = c("red", "blue"))
g_point <- ggplot(dt, aes(x = periodo, y = atr, colour = Talhão, shape = Talhão)) +
geom_point() +
geom_line() +
geom_label(aes(label = atr), position = position_nudge(y = 1.1),fontface = "bold")+
scale_y_continuous(limits = c(130,150))+
scale_shape_manual("Talhão", values = c(18, 19))+
geom_point(fill = "black", size = 3, stroke = 2)+
labs(x = "", y = "ATR", title = "", subtitle = "Evolução ATR")+
theme_gray()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x=element_text(face = "bold", size = 10, color = "black"),
plot.subtitle = element_text(size = 12, face = "bold"))+
scale_colour_manual(values = c("red", "blue"))
ggarrange(g_col + labs(x = "Período"), g_point + labs(x = "Período"),
ncol = 2, align = "v", common.legend = TRUE, legend = "right")
Patrick, welcome to Stackoverflow English! Ideally, the code should be reproducible. Plot data is missing from the code.
– Daniel Ikenaga
Daniel good observation !
– patrick cesar