首页 > 解决方案 > ggplot2 中带有 geom_text_contour 的标签上的小数点太多

问题描述

geom_contour_fill我需要通过添加标签来绘制 ggplot 中的多个数据集geom_text_contour,有时还会生成带有多个小数的标签。

例如对于这个数据集

library(ggplot2)
library(metR)
df <- read.csv("dataint.csv")
ggplot(df, aes(x = x, y = y, z = z)) +
    geom_contour_fill() +
    geom_text_contour(check_overlap = TRUE, stroke = 0.1, size = 3)

在此处输入图像描述

标签: rggplot2

解决方案


您可以考虑在整数处定义中断并将其用于两个层:

breaks = seq(16, 20, by = 0.4)
ggplot(df, aes(x = x, y = y, z = z)) +
  geom_contour_fill(breaks = breaks) +
  geom_text_contour(breaks = breaks,
                    check_overlap = TRUE, stroke = 0.1, size = 3)

在此处输入图像描述


推荐阅读