r - Adding a line to a blank R Plot
问题描述
So I have the following code that produced a blank canvas:
plot(1, type="n", xlab="Output", ylab="Real Interest Rate", xlim=c(9800, 10400), ylim=c(0.01, 0.07))
Now I am wondering how to get a line on the graph intersecting points (10000, 0.05) and (10200, 0.03).
I only want the line on my plot.
Any help is greatly appreciated!
解决方案
Base R - use the lines()
function.
x <- c(10000, 10200)
y <- c(0.05, 0.03)
plot(1,
type="n",
xlab="Output",
ylab="Real Interest Rate",
xlim=c(9800, 10400),
ylim=c(0.01, 0.07))
lines(x, y)
In ggplot2
, use geom_line()
.
library(ggplot2)
x <- c(10000, 10200)
y <- c(0.05, 0.03)
ggplot(data.frame(x, y), aes(x, y)) +
geom_line() +
scale_x_continuous(name = "Output",
limits = c(9800, 10400),
breaks = seq(9800, 10400, 100) +
scale_y_continuous(name = "Real Interest Rate",
limits = c(0.01, 0.07),
breaks = seq(0.01, 0.07, 0.02)) +
theme_bw()
推荐阅读
- wordpress - 运行 WP 的机器的副本仍然重定向到原始
- tensorflow - CNN + LSTM + CTC 用于 OCRing 英文单词和字母数字字符
- javascript - 联系表格电话号码验证错误PHP
- r - 将列表列表(顺便使用 read_docx 创建)转换为 data.frame
- amazon-web-services - AWS:通过 CLI 将 S3 文件名更改为小写
- adobe - Adobe Campaign Standard - 避免发送零字节文件
- django - Django更新和保存异步?
- javascript - 使用 ngClass 删除类时,如何确定元素以该类开头?
- ios - Alamofire 和 SwiftyJSON 获得价值
- android - Hello World 启动时出现黑屏