当x在R中为最大值时,如何求y的最小值?
我想找到y的最小值,其中x是最大值。当y最小时,我可以使用以下代码在绘图中添加一条线当x在R中为最大值时,如何求y的最小值?,r,ggplot2,R,Ggplot2,我想找到y的最小值,其中x是最大值。当y最小时,我可以使用以下代码在绘图中添加一条线 library(tidyverse) ggplot(data = df, aes(x = x, y = y)) + geom_point() + geom_hline(yintercept=min(df$y), size=1, color = "darkgreen") 现在,我如何在绘图中拟合一条线,其中x为最大值,y为最小值 资料 您可以对其进行筛选: yy <- df %&
library(tidyverse)
ggplot(data = df, aes(x = x, y = y)) + geom_point() +
geom_hline(yintercept=min(df$y), size=1, color = "darkgreen")
现在,我如何在绘图中拟合一条线,其中x为最大值,y为最小值
资料
您可以对其进行筛选:
yy <- df %>%
filter(x == max(x)) %>%
filter(y == min(y)) %>%
pull(y) %>%
first()
是否要将其放在
ggplot
中?我的意思是,在ggplot
之前过滤是否可以接受?如果它在ggplot
范围内,则会更好。
yy <- df %>%
filter(x == max(x)) %>%
filter(y == min(y)) %>%
pull(y) %>%
first()
ggplot(data = df, aes(x = x, y = y)) +
geom_point() +
geom_hline(yintercept=min(yy), size=1, color = "darkgreen")