2

使用这个 data.frame

数据

#import_data
df <- read.csv(url("https://www.dropbox.com/s/1fdi26qy4ozs4xq/df_RMSE.csv?raw=1"))

和这个脚本

library(ggplot2)
ggplot(df, aes( measured, simulated, col = indep_cumulative))+
  geom_point()+
  geom_smooth(method ="lm", se = F)+
  facet_grid(drain~scenario)

我得到了这个情节 在此处输入图像描述

我想RMSE为每个方面的左上角添加两个模型(独立和累积;仅两个值)。

我试过了

geom_text(data = df , aes(measured, simulated, label= RMSE))

它导致将 RMSE 值添加到刻面中的每个点。

对于将两个 RMSE 值仅添加到每个方面的左上角的任何帮助,我将不胜感激。

4

1 回答 1

2

如果您想为每个方面绘制两个数字,则需要进行一些数据准备以避免文本重叠。

library(dplyr)
df <- df %>%
  mutate(label_vjust=if_else(indep_cumulative == "accumulative",
                             1, 2.2))

在您的问题中,您明确告诉使用和ggplot2添加label=RMSE点。要在左上角添加标签,您可以使用和。所以代码将如下所示:x=measuredy=simulatedx=-Infy=Inf

ggplot(df, aes(measured, simulated, colour = indep_cumulative)) +
  geom_point() +
  geom_smooth(method ="lm", se = F) +
  geom_text(aes(x=-Inf, y=Inf, label=RMSE, vjust=label_vjust),
            hjust=0) +
  facet_grid(drain~scenario)

在此处输入图像描述

于 2017-01-15T08:24:13.017 回答