简体   繁体   English

散点图:使用多个变量更改X轴上的距离

[英]scatter plot : change distance in X-axis with multiple variable

I want to plot some numeral Data with scatter plot. 我想用散点图绘制一些数字数据。 I used the following code to plot the Data as a scatter with using the same axes for the different variables. 我使用以下代码将不同变量使用相同的轴将数据绘制为散点图。

library(car)
data("Anscombe")
mydat <- melt(Anscombe,"urban")
ggplot(mydat,aes(value,urban ))+geom_point() + 
     facet_grid(.~variable)+geom_smooth(method="lm", se=F)

here is the plot, and the range of x-axis value are the same for three variables. 这是曲线图,三个变量的x轴值范围相同。 I can not see the points of variable educations very well. 我不太清楚可变教育的要点。 plot1 plot1

so i try to change the range of x-axis. 因此,我尝试更改x轴的范围。 Below are the code. 下面是代码。

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)

Now the I can see the value of variable education. 现在,我可以看到可变教育的价值。 but the value of income is gone, because the value of income is > 450. plot2 但收入的价值消失了,因为收入值> 450 plot2

how can i change the x-axis value of each variables instead of change all? 如何更改每个变量的X轴值,而不是全部更改? I would be grateful if anybody can help me? 如果有人可以帮助我,我将不胜感激。

What you need is the additional argument scales = "free" : 您需要的是其他参数scales = "free"

ggplot(mydat, aes(value, urban)) + 
  geom_point() + 
  facet_grid(. ~ variable, scales = "free") + 
  geom_smooth(method = "lm", se = FALSE)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM