0
votes

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. I can not see the points of variable educations very well. plot1

so i try to change the range of x-axis. 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

how can i change the x-axis value of each variables instead of change all? I would be grateful if anybody can help me?

1

1 Answers

1
votes

What you need is the additional argument scales = "free":

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

enter image description here