Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11781

Customize label for an Interaction Plot

$
0
0

suppose I have the following data which summarizes the values of a dependent variable (dv) at low and high vales of a predictor (x) and a moderator (z)

dfx <- data.frame(x = rep(c(-0.909, 0.909),2),                  z = c(-0.676, -0.676, 0.676, 0.676),                  dv = c(448.8, 464.4, 462.8, 472.1))

I would like to draw the dv as a function of the predictor and the moderator by customizing **both **the type of lines and the markers

library(ggplot2)dfx$z <- as.factor(dfx$z) # turn the moderator as a factorggplot(dfx, aes(x=x, y = dv, colour=z, shape=z))+  geom_line()+  geom_point()+  scale_y_continuous("dv", limits = c(440,480))+  theme_classic()+  scale_colour_manual  ("A title", values=c("black", "black"), labels=c("-1SD", "+1SD"))+  scale_shape_manual   ("A title", values=c(2,15),labels=c("-1SD","+1SD"))

enter image description here

However, I would like to customize the linetype as well.

When I add

ggplot(dfx, aes(x=x, y = dv, colour=z, shape=z, linetype=z)

the following plot emerges. Yet I cannot either hide the second label or customize it throughscale_linetype_manual

enter image description here

Is there a way to fix this? I searched over the community but I could not find any method to overcome this problem. Also, when I suppress the second label, the key on it does not show both the type of line and mark.Any hint will be very much appreciated.


Viewing all articles
Browse latest Browse all 11781

Trending Articles