Ggplot boxplots with overlay scatter screen (same variables)

I am studying a bachelor's degree and over the past few months I have been teaching myself R. I just started trying ggplot and ran into some troubles. I made a series of crates, looking at the depth of the fish at different acoustic receiving stations. I would like to add a scatter chart that shows the depths of the receiving stations. This is what I have so far:

data    <- read.csv(".....MPS.csv", header=TRUE)
df      <- data.frame(f1=factor(data$Tagging.location), #$
                      f2=factor(data$Station),data$Detection.depth)
df2     <- data.frame(f2=factor(data$Station), data$depth)
df$f1f2 <- interaction(df$f1, df$f2) #$
plot1   <- ggplot(aes(y = data$Detection.depth, x = f2, fill = f1), data = df) + #$
                  geom_boxplot() + stat_summary(fun.data = give.n, geom = "text", 
                  position = position_dodge(height = 0, width = 0.75), size = 3)
                  plot1+xlab("MPS Station") + ylab("Depth(m)") +
                  theme(legend.title=element_blank()) + scale_y_reverse() + 
                  coord_cartesian(ylim=c(150, -10))
plot2   <- ggplot(aes(y=data$depth, x=f2), data=df2) + geom_point()
                  plot2+scale_y_reverse() + coord_cartesian(ylim=c(150,-10)) + 
                  xlab("MPS Station") + ylab("Depth (m)")

, , . x - "" ( 12 ), y - "" (0-150 ). ( 2 ). , .

, , "plot2" ( ) "plot1" boxplots ( ). ( ) Y.

, , R, ggplot , . !

+1
1

: , , , . .

1: . , ( ).

df <- data.frame(f1=factor(data$Tagging.location), f2=factor(data$Station), depth=data$Detection.depth)

df2 <- data.frame(f2=factor(data$Station), depth=data$depth)

2. "ggplot" `col = f1``. , boxplot, ( , ). , "geom", "ggplot". :

ggplot()+geom_boxplot(data=df, aes(x=f2, y=depth, col=f1)) + geom_point(data=df2, aes(x=f2, y=depth), colour="blue") + scale_y_reverse()

. , , , .

.

, , . , .

Depth chart

+2

Source: https://habr.com/ru/post/1529246/


All Articles