簡體   English   中英

R ggplot2 geom_point 消失

[英]R ggplot2 geom_point disappear

當我在以下數據上嘗試下面的代碼時,這些點在圖上消失了。

這可能是什么原因造成的?

樣本數據( df ):

structure(list(year = 1980:2021, AvgTMin = c(67.2833594069828, 
66.1884293276104, 69.5033078337241, 67.5901404824569, 67.6575292661207, 
67.5105525807862, 68.5233499715776, 68.3510672593276, 68.326288756069, 
68.32559571275, 69.857649104181, 70.0254370357328, 68.3083094663621, 
68.7337793145086, 70.7775163238103, 69.2169034146552, 68.1480784827241, 
69.9324034314914, 69.9568689931379, 68.2360121145603, 68.5744250002069, 
68.6254430718603, 69.2027051957672, 68.6790086484733, 68.4194284208621, 
67.9075792408276, 68.2006094435, 69.0469430709138, 68.7260982544224, 
68.2848526742414, 66.6119982602621, 69.5211913653448, 68.8781957073965, 
69.8467482637586, 68.9918181213448, 71.6258828067759, 70.4352370787155, 
70.1039310821983, 69.8729905482241, 70.6863166494138, 70.9844774828103, 
70.237952471931)), row.names = c(NA, -42L), class = c("tbl_df", 
"tbl", "data.frame"))

代碼:

library(tidyverse)

df %>% 
  ggplot(aes(x = year, y = AvgTMin)) +
  geom_point(aes(color = "Temperature"), size = 2, shape = 1, alpha = 0.1) +
  geom_smooth(method = lm, aes(linetype = "LM"), se = FALSE, color = "red") +
  scale_linetype_manual(values = 2, name = NULL) +
  scale_colour_manual(values = "deepskyblue4", name = NULL) +
  theme(text = element_text(size = 16)) +
  xlab("Year") +
  ylab("Minimum Temperature (F)") +
  ggtitle("1980-2021 Historical Trends") +
  guides(color = guide_legend(override.aes = list(alpha = 0.5), order = 1))

這是由於你的阿爾法。 將其更改為 alpha 0.5:

library(tidyverse)

df %>% 
  ggplot(aes(x = year, y = AvgTMin)) +
  geom_point(aes(color = "Temperature"), size = 2, shape = 1, alpha = 0.5) +
  geom_smooth(method = lm, aes(linetype = "LM"), se = FALSE, color = "red") +
  scale_linetype_manual(values = 2, name = NULL) +
  scale_colour_manual(values = "deepskyblue4", name = NULL) +
  theme(text = element_text(size = 16)) +
  xlab("Year") +
  ylab("Minimum Temperature (F)") +
  ggtitle("1980-2021 Historical Trends") +
  guides(color = guide_legend(override.aes = list(alpha = 0.5), order = 1))

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM