在折线图中的特定点创建另一个符号。

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

Create another symbol in specific point in a line graph

问题

我想在线图的特定点上有另一个符号,其中x轴的值为1。在我的图中,线上的所有点都有圆圈作为符号,但我想在x轴的值为1的地方有一个三角形。

到目前为止,我找到了这个帖子,其中创建了一个X符号,但当我在我的代码中使用它时,它会在圆圈上创建一个X标记,而我希望有一个全新的符号。

以下是代码:

library(ggplot2)

wd = "路径/"

block.data = read.csv(paste0(wd, "block.data.csv"))

ggplot(data = block.data, aes(x = PSF, y = CC, group = 1)) +
  geom_line() +
  geom_point(size = 2) + 
  theme_bw() + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + 
  scale_x_continuous(breaks = seq(0, 2, .2)) + 
  scale_y_continuous(breaks = seq(0.08, 23, .01))

和数据集:

structure(list(PSF = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 
1.8, 2), CC = c(0.08278661, 0.1866827, 0.2051862, 0.218509, 0.2247673, 
0.2268575, 0.2265966, 0.22522, 0.223409, 0.2213272, 0.2192285
)), class = "data.frame", row.names = c(NA, -11L))
英文:

I would like to have another symbol in a specific point of line graphs where the x axis has value of 1. In my graph, all the points in the line have circle as a symbol, but I would like to have a triangle where the value of the x axis is 1.

So far, I found this post when it creates an X symbol, but when I use it on my code, it creates an X mark on top the circle while I want an entirely new symbol.

Here is the code:

library(ggplot2)

wd = "path/"

block.data = read.csv(paste0(wd, "block.data.csv"))

ggplot(data = block.data, aes(x = PSF, y = CC, group = 1)) +
  geom_line() +
  geom_point(size = 2) + 
  theme_bw() + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + 
  scale_x_continuous(breaks = seq(0, 2, .2)) + 
  scale_y_continuous(breaks = seq(0.08, 23, .01))

And the dataset:
structure(list(PSF = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6,
1.8, 2), CC = c(0.08278661, 0.1866827, 0.2051862, 0.218509, 0.2247673,
0.2268575, 0.2265966, 0.22522, 0.223409, 0.2213272, 0.2192285
)), class = "data.frame", row.names = c(NA, -11L))

答案1

得分: 1

一种选择是在 shape 映射上设置条件,即 PSF != 1,并使用 scale_shape_manual 设置所需的形状:

library(ggplot2)

ggplot(data = block.data, aes(x = PSF, y = CC, group = 1)) +
  geom_line() +
  geom_point(aes(shape = PSF != 1), size = 3) +
  scale_shape_manual(values = c(17, 16)) +
  theme_bw() +
  theme(
    panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
    panel.background = element_blank(), axis.line = element_line(colour = "black")
  ) +
  scale_x_continuous(breaks = seq(0, 2, .2)) +
  scale_y_continuous(breaks = seq(0.08, 23, .01)) +
  guides(shape = "none")

在折线图中的特定点创建另一个符号。<!-- -->

英文:

One option would be to map a condition, i.e. PSF != 1 on the shape aes and set your desired shape using scale_shape_manual:

library(ggplot2)

ggplot(data = block.data, aes(x = PSF, y = CC, group = 1)) +
  geom_line() +
  geom_point(aes(shape = PSF != 1), size = 3) +
  scale_shape_manual(values = c(17, 16)) +
  theme_bw() +
  theme(
    panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
    panel.background = element_blank(), axis.line = element_line(colour = &quot;black&quot;)
  ) +
  scale_x_continuous(breaks = seq(0, 2, .2)) +
  scale_y_continuous(breaks = seq(0.08, 23, .01)) +
  guides(shape = &quot;none&quot;)

在折线图中的特定点创建另一个符号。<!-- -->

huangapple
  • 本文由 发表于 2023年2月27日 03:59:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574669.html
匿名

发表评论

匿名网友

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

确定