# \donttest{
library(mlbplotR)
library(ggplot2)
# create x-y-coordinates of a triangle and add league logo urls
df <- data.frame(
a = c(sin(2 * pi * (0:4) / 5), 0),
b = c(cos(2 * pi * (0:4) / 5), 0),
url = c(
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/virginia.svg",
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/michigan-st.svg",
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/lsu.svg",
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/texas.svg",
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/oregon.svg",
"https://i.turner.ncaa.com/sites/default/files/images/logos/schools/bgl/james-madison.svg"
)
)
# plot images directly from url
ggplot(df, aes(x = a, y = b)) +
geom_from_path(aes(path = url), width = 0.15) +
coord_cartesian(xlim = c(-2, 2), ylim = c(-1.3, 1.5)) +
theme_void()
# plot images directly from url and apply transparency
ggplot(df, aes(x = a, y = b)) +
geom_from_path(aes(path = url), width = 0.15, alpha = 0.5) +
coord_cartesian(xlim = c(-2, 2), ylim = c(-1.3, 1.5)) +
theme_void()
# It is also possible and recommended to use the underlying Geom inside a
# ggplot2 annotation
ggplot() +
annotate(
mlbplotR::GeomFromPath,
x = 0,
y = 0,
path = "https://a.espncdn.com/combiner/i?img=/i/teamlogos/leagues/500/mlb.png",
width = 0.4
) +
theme_minimal()
# }
Run the code above in your browser using DataLab