0

I am doing a multiple regression in r and want to show my regression line. I am using the following code:

ggplot(data = data_all, mapping = aes(x = wsignatory, y = Lifetime_CO2)) +
  geom_point(alpha = 0.5, aes(col=wequity_dummy)) +
  geom_smooth(method = lm) +
  coord_cartesian(ylim = c(0, 200)) +
  theme_bw() +
  xlab("Weighted Signatory Variable") + 
  ylab("Lifetime CO2 Emissions")
ggsave("plot_Lifetime_CO2.jpeg")

My data includes a dummy variable called wloan_dummy, and I want to color does observation points in my plot that have wloan_dummy == 1. So far, my code shows a color range and the dots appear in light blue, blue, dark blue and black. But as wloan_dummy is a dummy, there should only be two color types. Anybody knows what the reason could be?

Lilly
  • 17
  • 5
  • 3
    Hi Lilly - It will be easier to help if you can please show a sample of the data. Most likely you need to treat your dummy variable as a `factor`. – Seth Mar 29 '23 at 14:38
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. It's hard to know for sure what this code does without seeing the data you are passing in. – MrFlick Mar 29 '23 at 14:55
  • I tried the first comment and as `factor` worked. Thanks a lot! Next time I will add a reproducible example! :) – Lilly Mar 30 '23 at 11:26

0 Answers0