R基础绘图—散点图&线图
title: “R Graph”
author: “intro”
date: “2022/1/18”
output:
pdf_document: default
html_document: default
在这里插入代码片
knitr::opts_chunk$set(echo = TRUE)
Basic Graph Functions
scatter plot
cars <- cars
str(cars)
head(cars)
cars <- cars
str(cars)
head(cars)
plot(cars$dist~cars$speed, # y~x
pch=19,#Set the plotting symbol to filled dots
col='lightblue',#Set the color of plotting symbol to red
main="Relationship between car distance & speed", # Plot aTitle
xlab="Speed (miles per hour)", #X axis title
ylab="Distance travelled (miles)", #Y axis title
xlim=c(0,30), #Set x axis limits from 0 to 30
ylim=c(0,140), #Set y axis limits from 0 to 140
xaxs="i", #Set x axis style as internal
yaxs="i", #Set y axis style as internal
)
line graphs
plot(cars$dist~cars$speed,
type="l", #Specify type of plot as l for line
col='blue',
main="Relationship between car distance & speed",
xlab="Speed miles per hour",
ylab="Distance travelled (miles)")