ggplot 线图在轴上出现问题“您是说 `limits = factor(...)` 还是 `scale_*_continuous()`?”

问题描述 投票:0回答:0

我是 R 和 ggplot 的初学者,一直面临着在线图上定义 x 轴和 y 轴的问题。

我有以下名为英国的数据集:enter image description here

我想用

绘制床比演变
  • x 轴从 2010 年到 2021 年,间隔为 1
  • y 轴从 0 到 3,间隔为 0,5

我编码如下:

ggplot(data=UK, aes(x = Year, y = Beds_1000, group = 1)) + geom_line(color = as.factor("red")) + geom_point() + scale_x_discrete(limits=c(2010,2021)) + scale_y_discrete(limits=c(0,3), break)

但是,我的图形轴消失了,我收到以下消息:“连续限制提供给离散刻度。 ℹ 你是说

limits = factor(...)
还是
scale_*_continuous()
?”

我尝试使用这两个建议,但没有任何区别。

如果有人能帮助我解决这个问题,我将不胜感激。 谢谢。

我尝试使用 limits=factor() 和 scale_*_continuous() 但它对最终图表没有影响。如果没有这些功能,轴消失或保持不变。

ggplot2 axis linegraph
© www.soinside.com 2019 - 2024. All rights reserved.