ggplot_forest | R Documentation |
Intern wird geom_pointrange verwendet
Alternating Background Colour
Add alternating background color along the y-axis. The geom takes default
aesthetics odd
and even
that receive color codes. The codes
would preferably be in the 8-hex ARGB format to allow for transparency if
the geom is meant to be used as visual background.
Horizontal Study Effects with Confidence Intervals
Builds a custom version of geom_pointrangeh
.
ggplot_forest(
data,
name = term,
estimate = estimate,
conf.low = conf.low,
conf.high = conf.high,
se = NULL,
groups = NULL,
colour = NULL,
shape = NULL,
logodds = FALSE,
col.strip = c(even = "#00000000", odd = "#33333333"),
col = NULL,
cex = 1,
cex.pch = 1.2,
cex.pch.legende = cex.pch,
dodge.width = 0.5,
pch = c(21L, 22L, 23L, 24L, 25L),
main = NULL,
xlab = NULL,
xlim = NULL,
xtickbreaks = NULL,
legend.title = ggplot2::waiver(),
...
)
geom_stripes(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
show.legend = NA,
inherit.aes = TRUE
)
geom_effect2(
mapping = NULL,
data = NULL,
stat = "identity",
dodge.width = 0.5,
position = ggplot2::position_dodge(width = dodge.width),
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
theme_forest(
base_size = 13,
base_line_size = base_size/22,
base_rect_size = base_size/22
)
data |
The data to be displayed in this layer. There are three options: If A A |
name , estimate , se , pvalue |
the variable |
groups , colour , shape |
the variable |
logodds |
logical (defaults to FALSE) |
col.strip , col |
Farbe strips und Symbole col.strip =NULL keine strips |
cex |
size |
cex.pch |
pch size symbol |
dodge.width |
abstand bei Gruppen zwischen den Balken |
legend.title |
Beschriftung main, xlab |
... |
main, xlab, graphical parameters |
mapping |
Set of aesthetic mappings created by |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
If |
df |
A data frame |
Visualize multiple measures of effect with their confidence intervals in a vertical layout.
stolen from https://github.com/NightingaleHealth/ggforestplot
Anmerkung: ggforestplot scheint nicht mehr betreut zu werden - manche ggplot Funktionen sind nict mehr aktuell!
Ilari Scheinin
# ----------------------------------------
# Draw a Forestplot of Measures of Effects
# ----------------------------------------
require(magrittr)
require(ggplot2)
require(stp25plot)
load(
"C:/Users/wpete/Dropbox/1_Projekte/002-NURMI/791_Martina_Gregori/dummy-forest-df.Rdata"
)
data$std.error[is.na(data$estimate)] <- 0
data$conf.low[is.na(data$estimate)] <- 0
data$conf.high[is.na(data$estimate)] <- 0
data$estimate[is.na(data$estimate)] <- 0
data <- data[-which(data$var == "age"), ]
data <- data[-which(data$var == "(Intercept)"), ]
data$level <- factor(data$level,
c("M/UM", "HM" , "10 km"),
c("M/UM", "HM", "10 km (Reference)"))
dotCOLS = c( "#74C476","#9E9AC8","#f9b282")
barCOLS = c("#006D2C" , "#756BB1","#A63603")
ggplot_forest(
data,
name = group,
groups = level ,
title = "Associations to Running",
xlab = "Estimate (95% CI)",
legend.title = "legend title using guide",
col = barCOLS,
cex.pch = 3,
cex = 1.1,
# cex.pch = 1,
pch = c(19, 15, 17)
)
#----------------------------
# Alternative geom_pointrange
#----------------------------
ggplot(data = data, aes(x = group , y = estimate)) +
geom_pointrange(
mapping = aes(
ymin = conf.low ,
ymax = conf.high,
color = level,
shape = level
),
position = ggplot2::position_dodge(width = 0.5)
) +
GGally::geom_stripped_cols(odd = "#00000000", even = "#11111111") +
ggplot2::guides(
colour = guide_legend(
reverse = TRUE,
title = "legend.title",
override.aes = list(linewidth = 1)
),
shape = guide_legend(reverse = TRUE, title = "legend.title")
) +
scale_color_manual(values = dotCOLS) +
stp25plot::theme_forest(base_size = 12) +
coord_flip()
#-----------------------------
#' # Alternative geom_errorbar
#-----------------------------
ggplot(data = data, aes(x = group, y = estimate)) +
geom_point(
mapping = aes(
color = level,
shape = level
),
position = ggplot2::position_dodge(width = 0.5)
) +
geom_errorbar(
mapping = aes(
ymin = conf.low ,
ymax = conf.high,
color = level,
width = 0.2
),
position = ggplot2::position_dodge(width = 0.5)
) +
GGally::geom_stripped_cols(odd = "#00000000", even = "#11111111") +
coord_flip() +
scale_color_manual(values = dotCOLS) +
stp25plot::theme_forest(base_size = 12)
#---------------------------
# Alternative geom_linerange
#---------------------------
p <- ggplot(data,
aes(
x = group,
y = estimate,
ymin = conf.low ,
ymax = conf.high,
col = level,
fill = level
)) +
#specify position here
#geom_hline(yintercept = c(0, 20, 40, 60), lty = 2) +
# geom_vline(xintercept = seq(0, 15) + .5, lty = 2, col = "gray") +
geom_linerange(linewidth = 3, position = position_dodge(width = .7)) +
#specify position here too
geom_point(
size = 3,
shape = 21,
colour = "white",
stroke = 0.5,
position = position_dodge(width = .7)
) +
# scale_fill_manual(values = barCOLS) +
# scale_color_manual(values = dotCOLS) +
guides(
colour = guide_legend(reverse=TRUE),
fill = guide_legend(reverse=TRUE)
) +
scale_x_discrete(name = "") +
scale_y_continuous(name = "Estimate 95% CI", limits = c(-10, 5)) +
coord_flip() +
stp25plot::theme_forest(base_size = 12)
# theme_minimal() +
# theme(
# panel.grid.major = element_blank(),
# panel.grid.minor = element_blank())
p +
scale_fill_manual(values = barCOLS) +
scale_color_manual(values = dotCOLS)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.