<- squircensus |>
squirrelplot ggplot(aes(
x = numberofsquirrels,
y = temperature,
color = temperature)) +
geom_point(alpha = 0.3)+
scale_color_gradient(
low = "#790033", high = "#ee3a83",
aesthetics = "color") +
labs(title = "squirrels by temperature")
squirrelplot
GGPLOT2 RNOTES
Lollipop
<- read_csv("assaultavg.csv")
assaultavg <- read_csv("assaultfirstall.csv")
assaultfirstall <- mean(assaultfirstall$sentencelength)
meanlength
|>
assaultavg ggplot(aes(x = race, y = sentencelength)) +
geom_segment(aes(x = race,
y = meanlength,
xend = race,
yend = sentencelength)) + # creates lines leading to each dot
# LAYEZRING this
geom_point(size = 7,color = "#FFB384", alpha = 0.8) +
# text label
geom_text(aes(label = count), size = 3) +
# Layering dots
geom_point(size = 7,
color = "#FFB384",
alpha = 0.3) + # creates dots for racial group means
# make first one bolded (aka layer it on top of itself over the lollipops)
geom_text(aes(label = "260"), size = 3, x = 1, y = 3155.412) +
geom_text(aes(label = "prisoners"), size = 3.2, x = 1.235, y = 3155.412) +
geom_hline(yintercept = meanlength, color = "#3d3b3c", size = .5) + # creates the main horizontal line
labs(x = "Race",
y = "Sentence Length (days)",
title = "Average Sentence Length per Race for 1st-Degree Assault") +
theme_minimal(base_size = 12, base_family = "serif")
+
squirrelplot theme(axis.line = element_line(linewidth = 1, colour = "#560628",
arrow = arrow(
angle = 40, length = unit(0.3, "inches"),
ends = "both",
type = "open")), # open/closed arrow
axis.ticks = element_line(linewidth = 5, colour = "#af1c59"),
# panel grid
panel.grid.major = element_line(colour = "#300014",
linewidth = 0.2), # type 0 to remove
# adjust the labels: either axis.title or axis.text
axis.text.y = element_text(size = rel(1), angle = 90), # rel is "specify sizes relative to the parent"
# remove the label altogether
axis.title.x = element_blank(),
# adjust title: plot.title
plot.title = element_text(size = 20),
# adjust labels
axis.text = element_text(colour = "#300014", size = rel(0.8))
)
# another thing you can do with "arrow"
+
squirrelplot theme(axis.line = element_line(linewidth = 1, colour = "#560628",
arrow = arrow(
angle = 90, length = unit(6, "inches"),
# first, last, or both(!)
ends = "both",
type = "open")))
Straight from ggplot2.tidyverse.org
+ theme(
squirrelplot panel.background = element_rect(fill = "transparent"), # or color
plot.margin = margin(2, 2, 2, 2, "cm"),
plot.background = element_rect(
fill = "grey90",
colour = "black",
linewidth = 1
) )
|>
assaultavg ggplot(aes(x = race, y = sentencelength)) +
geom_segment(aes(x = race,
y = meanlength,
xend = race,
yend = sentencelength)) + # creates lines leading to each dot
# LAYEZRING this
geom_point(size = 7,color = "#FFB384", alpha = 0.8) +
# text label
geom_text(aes(label = count), size = 3) +
# Layering dots
geom_point(size = 7,
color = "#FFB384",
alpha = 0.3) + # creates dots for racial group means
# make first one bolded (aka layer it on top of itself over the lollipops)
geom_text(aes(label = "260"), size = 3, x = 1, y = 3155.412) +
geom_text(aes(label = "prisoners"), size = 3.2, x = 1.2, y = 3155.412) +
geom_hline(yintercept = meanlength, color = "#3d3b3c", size = .5) + # creates the main horizontal line
labs(x = "Race",
y = "Sentence Length (days)",
title = "Average Sentence Length per Race for 1st-Degree Assault") +
theme_minimal(base_size = 12, base_family = "serif")