Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206531

How to plott an Interaction with categorical data (Example)

$
0
0

I know I have an Interaction on Posture and Sex and I want to visualize it. But it doesn't work as the picture shows (why are there vertical lines?)

I let rank pictures (with in differences in Gender (m/f) and Postures (Open/Closed)) in Intelligence (Ranking from 1 to 4)

y is always Intelligence.

I hoped to get along with # y_mean <- mean(y) , that I get the mean of Intelligence for f/m and open/closed, but this doesn't work.

I'm thankful for any advice or alternatives...

I base my code on http://philippmasur.de/blog/2018/11/26/visualizing-interaction-effects/

That'S the plot I get[1]

My Code was

library(ggplot2)

data2<-ForkinDatenElefant


y<- data2$Intelligence
m1 <-Sex
m2 <-Pos

# y_mean <- mean(y)

)

y_se <- std(y)  
# Creating the plot
data2 %>% 
  ggplot(aes(x = m1, 
             y = y, 
             color = m2)) +
  geom_line(aes(group = m2)) +
  geom_point() 
#+
#    geom_errorbar(aes(ymin = y_mean-1.96*y_se, 
                    ymax = y_mean+1.96*y_se),
                width = .1) +
 # ylim(0, 5) +
  labs(x = "Sex",
       color  = "Pos",
       y = "Dependent Variable") +
  theme_minimal() +
  scale_color_brewer(palette = "Blues")

```


Viewing all articles
Browse latest Browse all 206531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>