p1 <- ggplot(data= <DATA>) +
aes(<MAPPINGS>) +
<GEOM_FUNCTION>(aes(<MAPPINGS>),
stat=<STAT>,
position=<POSITION>) +
<COORDINATE_FUNCTION> +
<FACET_FUNCTION>
print(p1)
ggsave(plot=p1,
filename="MyPlot",
width=5,
height=3,
units="in",
device="pdf")
Use package Inkscape
## tibble [234 × 11] (S3: tbl_df/tbl/data.frame)
## $ manufacturer: chr [1:234] "audi" "audi" "audi" "audi" ...
## $ model : chr [1:234] "a4" "a4" "a4" "a4" ...
## $ displ : num [1:234] 1.8 1.8 2 2 2.8 2.8 3.1 1.8 1.8 2 ...
## $ year : int [1:234] 1999 1999 2008 2008 1999 1999 2008 1999 1999 2008 ...
## $ cyl : int [1:234] 4 4 4 4 6 6 6 4 4 4 ...
## $ trans : chr [1:234] "auto(l5)" "manual(m5)" "manual(m6)" "auto(av)" ...
## $ drv : chr [1:234] "f" "f" "f" "f" ...
## $ cty : int [1:234] 18 21 20 21 16 18 18 18 16 20 ...
## $ hwy : int [1:234] 29 29 31 30 26 26 27 26 25 28 ...
## $ fl : chr [1:234] "p" "p" "p" "p" ...
## $ class : chr [1:234] "compact" "compact" "compact" "compact" ...
##
## c d e p r
## 1 5 8 52 168
# basic scatter plot
ggplot(data=d) +
aes(x=displ,y=hwy) +
geom_point() +
geom_smooth() +
geom_smooth(method="lm",col="red")
# add a linear regression line
ggplot(data=d) +
aes(x=displ,y=hwy) +
geom_point() +
geom_smooth(method = "lm",col="red")
# bar plot with specified counts or meansw
x_treatment <- c("Control","Low","High")
y_response <- c(12,2.5,22.9)
summary_data <- data.frame(x_treatment,y_response)
ggplot(data=summary_data) +
aes(x=x_treatment,y=y_response) +
geom_col(fill=c("grey50","goldenrod","goldenrod"),col="black")
# basic curves and functions
my_vec <- seq(1,100,by=0.1)
# plot simple mathematical functions
d_frame <- data.frame(x=my_vec,y=sin(my_vec))
ggplot(data=d_frame) +
aes(x=x,y=y) +
geom_line()
# use theme parameters to modify font and font size
p1 + theme_classic(base_size=40,base_family="serif")