ggplot() + geom_path(data = world_map, aes(x = long, y = lat, group = group), color = "gray") + geom_point(data = baiyang_data, aes(x = Longitude, y = Latitude), color = "white") + geom_point(data = qingyang_data, aes(x = Longitude, y = Latitude), color = "lightgreen") + geom_point(data = heiyang_data, aes(x = Longitude, y = Latitude), color = "black") + geom_point(data = daye_data, aes(x = Longitude, y = Latitude), color = "yellowgreen") + geom_point(data = huyang_data, aes(x = Longitude, y = Latitude), color = "orange") + ggtitle("map")这段代码为什么显示Discrete value supplied to continuous sxale
时间: 2024-02-27 10:51:58 浏览: 276
22. R语言—ggplot2_线形参数geom_line大全.pdf
5星 · 资源好评率100%
这个错误通常发生在尝试将离散型变量(如字符或因子)应用于连续型比例尺(如x或y轴)时。在这段代码中,这个错误可能是因为x和y轴的数据类型不是连续型的,而是离散型的,因为你使用了地理坐标数据。
解决这个问题的方法是,将x和y轴的比例尺设置为离散型比例尺,使用scale_x_discrete()和scale_y_discrete()函数可以帮助你设置适当的比例尺。例如,下面是一些修改代码的示例:
```
ggplot() +
geom_path(data = world_map, aes(x = long, y = lat, group = group), color = "gray") +
geom_point(data = baiyang_data, aes(x = Longitude, y = Latitude), color = "white") +
geom_point(data = qingyang_data, aes(x = Longitude, y = Latitude), color = "lightgreen") +
geom_point(data = heiyang_data, aes(x = Longitude, y = Latitude), color = "black") +
geom_point(data = daye_data, aes(x = Longitude, y = Latitude), color = "yellowgreen") +
geom_point(data = huyang_data, aes(x = Longitude, y = Latitude), color = "orange") +
scale_x_discrete() +
scale_y_discrete() +
ggtitle("map")
```
这样就可以将x和y轴的比例尺设置为离散型比例尺,解决这个问题。
阅读全文