# R线图示例图解

## 本文概述

``plot(v, type, col, xlab, ylab)``

S.No Parameter Description
1. v 它是一个包含数值的向量。
2. type 该参数取值” I”。只画线还是？只画点, 用” o”画线和点。
3. xlab 它是x轴的标签。
4. ylab 它是y轴的标签。
5. main 它是图表的标题。
6. col 它用于为点和线都提供颜色

### 例子

``````# Creating the data for the chart.
v <- c(13, 22, 28, 7, 31)
# Giving a name to the chart file.
png(file = "line_graph.jpg")
# Plotting the bar chart.
plot(v, type = "o")
# Saving the file.
dev.off()``````

## 折线图标题, 颜色和标签

### 例子

``````# Creating the data for the chart.
v <- c(13, 22, 28, 7, 31)
# Giving a name to the chart file.
png(file = "line_graph_feature.jpg")
# Plotting the bar chart.
plot(v, type = "o", col="green", xlab="Month", ylab="Temperature")
# Saving the file.
dev.off()``````

## 包含多条折线的折线图

lines()函数采用附加输入向量来创建线。让我们看一个例子来了解如何使用此功能：

### 例子

``````# Creating the data for the chart.
v <- c(13, 22, 28, 7, 31)
w <- c(11, 13, 32, 6, 35)
x <- c(12, 22, 15, 34, 35)
# Giving a name to the chart file.
png(file = "multi_line_graph.jpg")
# Plotting the bar chart.
plot(v, type = "o", col="green", xlab="Month", ylab="Temperature")
lines(w, type = "o", col = "red")
lines(x, type = "o", col = "blue")
# Saving the file.
dev.off()``````

## 使用ggplot2的线图

### 例子

``````library(ggplot2)
#Creating data for the graph
data_frame<- data.frame(dose=c("D0.5", "D1", "D2"), len=c(4.2, 10, 29.5))
png(file = "multi_line_graph2.jpg")
# Basic line plot with points
ggplot(data=data_frame, aes(x=dose, y=len, group=1)) +geom_line()+geom_point()
# Change the line type
ggplot(data=df, aes(x=dose, y=len, group=1)) +geom_line(linetype = "dashed")+geom_point()
# Change the color
ggplot(data=df, aes(x=dose, y=len, group=1)) +geom_line(color="red")+geom_point()
dev.off()``````

• 回顶