简体   繁体   中英

How do I change the axis colour when using ggpredict() and plot()?

I'm trying to create a scatter graph of a linear model. I have successfully created the graph using ggPredict and plot but the axis is coming out light grey (barely visible) no matter what I put in to change it:

self_acc2 <- ggpredict(model1, "mean.self")
plot(self_acc2)
p.model7 <- plot(self_acc2)
self_acc <- p.model7 +
  geom_point(data = dat_excluded, aes(x = mean.self, y = mean.acc),
             alpha = 0.5, colour = "blue", shape = "circle") +
  geom_line(size = 1) + 
  xlim(0, 9) +
  ylim(0, 1) +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor= element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(colour = "black")) +
  xlab("Self-Rated Accuracy") +
  ylab("Mean accuracy") +
  ggtitle("Relationship Between Self-Rated Accuracy and Actual Accuracy of Health Understanding")
self_acc

I used:

theme(axis.line = element_line(colour = "black"))

but this didn't affect the colour

I also tried:

 plot(self_acc, colors="bw")

but this didn't change anything.

I also need to put axis tick marks and nothing is working for that either.

(I've only been using R for a few months, sorry if this is really basic! I also don't know how to properly lay this question out so I hope this is ok)

You could use axis.line.x.bottom and axis.line.y in your theme . I used the mtcars dataset to make it reproducible:

library(ggeffects)
library(ggplot2)
model1 <- lm(mpg~hp, data = mtcars)
self_acc2 <- ggpredict(model1, "hp")
p.model7 <- plot(self_acc2)
p.model7 +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor= element_blank(),
    panel.background = element_blank(),
    axis.line.x.bottom = element_line(colour = "black"),
    axis.line.y = element_line(colour = 'black')) 

Created on 2023-01-14 with reprex v2.0.2


If you want to add tick marks you can use axis.ticks :

p.model7 <- plot(self_acc2)
p.model7 +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor= element_blank(),
    panel.background = element_blank(),
    axis.ticks = element_line(colour = "black"),
    axis.line.x.bottom = element_line(colour = "black"),
    axis.line.y = element_line(colour = 'black')) 

Created on 2023-01-14 with reprex v2.0.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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