r语言如何绘制图形如下: dose<-c(20,30,40,45,60) drugA<-c(16,20,27,40,60) drugB<-c(15,18,25,31,40),画图dose为自变量,drugA和drugB分别为因变量,类型为”b”的图形,线型为1与2,线宽度为2,点类型为15和17,颜色为红色与蓝色,主标题为DrugAvs DrugB,X轴标签为Dosage,Y轴标签为DrugResponse,X轴范围10-60,Y轴0-70,添加x=40的垂直黄色yellow参考线,添加y=30的水平灰色grey参考线,同时在图形左上方添加相应图形线的放缩0.5倍的图例(legend).
时间: 2024-03-07 17:47:45 浏览: 62
R软件绘图操作
以下是使用R语言绘制图形的代码:
```
# 创建数据
dose <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
# 绘制图形
plot(dose, drugA, type = "b", lty = 1, lwd = 2, pch = 15, col = "red",
ylim = c(0, 70), xlim = c(10, 60), xlab = "Dosage", ylab = "DrugResponse",
main = "DrugA vs DrugB")
lines(dose, drugB, type = "b", lty = 2, lwd = 2, pch = 17, col = "blue")
abline(v = 40, col = "yellow") # 添加垂直黄色参考线
abline(h = 30, col = "grey") # 添加水平灰色参考线
legend("topleft", legend = c("DrugA", "DrugB"), lty = c(1, 2), lwd = 2, pch = c(15, 17),
col = c("red", "blue"), bty = "n", cex = 0.5) # 添加图例
```
运行以上代码将得到所需的图形。
阅读全文