使用geom_path在红色中填充一个心形。

huangapple go评论76阅读模式
英文:

fill a heart in red with geom_path

问题

You can fill the plot in red by adding the fill aesthetic to geom_path in your ggplot code. Here's the modified code:

ggplot(data = h, aes(x = x, y = y)) + 
  geom_path(color = "maroon", fill = "red") +
  theme_void()

This change will fill the path in red while keeping the maroon color for the lines.

英文:

I have this plot:

h <- 
  data_frame(t = seq(0, (2 * pi), by = 0.005), 
             x = 13 * sin(t)^3, 
             y = 13 * cos(t) - 
               5 * cos(2 * t) - 
               2 * cos(3 * t) - 
               1 * cos(4 * t),
             chunk = floor(x)) %>%
  select(-t) 


ggplot(data = h, aes(x = x, y = y)) + 
  geom_path(color = "maroon")+
  theme_void()

使用geom_path在红色中填充一个心形。

How can I fill it in red ?
I do not know how to do it with geom_path.

答案1

得分: 1

geom_path没有fill美学属性,因为它用于创建路径,而不是闭合的形状。请改用geom_polygon代替:

ggplot(data = h, aes(x = x, y = y)) + 
  geom_polygon(fill = "red") +
  theme_void()
英文:

geom_path does not have a fill aesthetic, because it is used to create a path, not closed shapes. Use geom_polygon instead:

ggplot(data = h, aes(x = x, y = y)) + 
  geom_polygon(fill = "red") +
  theme_void()

使用geom_path在红色中填充一个心形。

huangapple
  • 本文由 发表于 2023年5月22日 15:57:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定