散点图:使用多变量改变 X 轴的距离
scatter plot : change distance in X-axis with multiple variable
我想用散点图绘制一些数字数据。我使用以下代码将数据绘制为散点图,并对不同的变量使用相同的轴。
library(car)
data("Anscombe")
mydat <- melt(Anscombe,"urban")
ggplot(mydat,aes(value,urban ))+geom_point() +
facet_grid(.~variable)+geom_smooth(method="lm", se=F)
这是绘图,三个变量的 x 轴值范围相同。我不太清楚可变教育的要点。
plot1
所以我尝试更改 x 轴的范围。下面是代码。
ggplot(mydat,aes(value,urban ))+geom_point() +
facet_grid(.~variable)+ geom_smooth(method="lm", se=F)+
coord_cartesian(xlim = c(0,450), ylim = NULL, expand = TRUE)
现在我看到了可变教育的价值。但是income的值没有了,因为income的值>450。
plot2
如何更改每个变量的 x 轴值而不是全部更改?如果有人能帮助我,我将不胜感激?
你需要的是附加参数scales = "free"
:
ggplot(mydat, aes(value, urban)) +
geom_point() +
facet_grid(. ~ variable, scales = "free") +
geom_smooth(method = "lm", se = FALSE)
我想用散点图绘制一些数字数据。我使用以下代码将数据绘制为散点图,并对不同的变量使用相同的轴。
library(car)
data("Anscombe")
mydat <- melt(Anscombe,"urban")
ggplot(mydat,aes(value,urban ))+geom_point() +
facet_grid(.~variable)+geom_smooth(method="lm", se=F)
这是绘图,三个变量的 x 轴值范围相同。我不太清楚可变教育的要点。 plot1
所以我尝试更改 x 轴的范围。下面是代码。
ggplot(mydat,aes(value,urban ))+geom_point() +
facet_grid(.~variable)+ geom_smooth(method="lm", se=F)+
coord_cartesian(xlim = c(0,450), ylim = NULL, expand = TRUE)
现在我看到了可变教育的价值。但是income的值没有了,因为income的值>450。 plot2
如何更改每个变量的 x 轴值而不是全部更改?如果有人能帮助我,我将不胜感激?
你需要的是附加参数scales = "free"
:
ggplot(mydat, aes(value, urban)) +
geom_point() +
facet_grid(. ~ variable, scales = "free") +
geom_smooth(method = "lm", se = FALSE)