'Remove margin from ggplot2 graph with no axes or grid
How may I remove the area shaded red in the graph attached? I have tried all advise out there and still, nothing!! Below is my code for that top graph. I would like to have the top graph being only text, with the text starting at the start of the plot margins (where the border is), as opposed to where the current location. Please advise....
perf.overall <-1.4
perf.lt7.lt2 <- -1.3
perf.lt7.gt2 <- 1.2
perf.gt7 <- -1.1
current.performance <- 6
perf.peers <- -4
data <- data.frame()
green.good <- "#37D111"
red.bad <- "#FF1919"
text.graph <- ggplot(data) +
geom_blank() +
theme_void() +
geom_text(aes(x = 1.55, y = 8.0), size = 5.5,
family = "Candara",
label = paste0("Performance Goal: < 1% errors")) +
geom_text(aes(x = 1.475, y = 7.5), size = 5.5,
family = "Candara",
label = paste0("Errors this month: ")) +
geom_text(aes(x = 3.5, y = 7.5), size = 5.5,
family = "Candara",
label = paste0(current.performance ,"% "),
colour = ifelse(current.performance < 1, green.good, red.bad)) +
geom_text(
aes(x = 3.8, y = 7.5), size=11,
label = ifelse(current.performance < 1, emo::ji("+1"), emo::ji("-1"))
) +
geom_text(aes(x = 1.45, y = 6.8), size = 5.5,
family = "Candara",
label = paste0("Since last month: ")) +
geom_text(aes(x = 2.15, y = 6.3), size = 4,
family = "Candara",
label = paste0("Performance for Age < 7 days & Birth Weight < 2kg ",
ifelse(perf.lt7.lt2 > 0,"worsened", "improved"),
" by: ")) +
geom_text(aes(x = 3.5, y = 6.3), size = 4,
family = "Comic Sans MS",
label = paste0(abs(perf.lt7.lt2), "% "),
colour = ifelse(perf.lt7.lt2 < 0, green.good, red.bad)) +
geom_text(aes(x = 2.15, y = 5.8), size = 4,
family = "Candara",
label = paste0("Performance for Age < 7 days & Birth Weight >= 2kg ",
ifelse(perf.lt7.gt2 > 0,"worsened", "improved"),
" by: ")) +
geom_text(aes(x = 3.5, y = 5.8), size = 4,
family = "Comic Sans MS",
label = paste0(abs(perf.lt7.gt2), "% "),
colour = ifelse(perf.lt7.gt2 < 0, green.good, red.bad)) +
geom_text(aes(x = 1.825, y = 5.3), size = 4,
family = "Candara",
label = paste0("Performance for Age 7-28 days ",
ifelse(perf.gt7 > 0,"worsened", "improved"),
" by: ")) +
geom_text(aes(x = 3.5, y = 5.3), size = 4,
family = "Comic Sans MS",
label = paste0(abs(perf.gt7), "% "),
colour = ifelse(perf.gt7 < 0, green.good, red.bad)) +
geom_text(x = 1.15, y = 4.4, size=10,
label = emo::ji("backhand_index_pointing_right_medium_dark_skin_tone")) +
geom_text(aes(x = 1.65, y = 4.3), size = 4.5,
family = "Corbel",
label = "To improve, check: ") +
geom_text(aes(x = 1.45, y = 3.8), size = 4.5,
family = "Corbel",
label = "1. The age of the baby") +
geom_text(aes(x = 1.48, y = 3.3), size = 4.5,
family = "Corbel",
label = "2. The weight of the baby") +
geom_text(aes(x = 1.4, y = 2.8), size = 4.5,
family = "Corbel",
label = "3. Use the BPP chart") +
geom_text(aes(x = 2.6, y = 3.7), size = 4.5,
family = "Corbel",
label = emo::ji("bubble")) +
geom_label(aes(
x = 3.2,
y = 3.5,
family = "Comic Sans MS",
label = "Gentamcin overdose causes\nkidney and hearing problems"
)
) +
#
#
labs(
title = paste0("Our monthly score card: January 2022"),
y = NULL,
x = NULL
) +
theme(
plot.background = element_rect("#EBEBEB"),
panel.background = element_blank(),
panel.border = element_blank(),
plot.title = element_text(size=20, family="Stencil"),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks.length = unit(0.0001, "mm"),
plot.margin = margin(0.1,0,0,0, "pt"), #unit(c(0.1,0,0,0), "cm"),
panel.spacing=unit(c(0,0,0,0), "pt")
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

