在绘图函数中无法绘制点。

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

points not plotting in plot function

问题

我尝试在栅格层的特定坐标上绘制点。

    > head(coords_df)
         x    y
    1 66.5 66.5
    2 67.0 66.5
    3 67.5 66.5
    4 68.0 66.5
    5 68.5 66.5
    6 69.0 66.5

我尝试使用以下方式绘制:

    plot(CNRM_1)
    points(coords_df, pch=16)

栅格图绘制出来了,但点没有显示出来。请帮助我找到问题所在。

    > dput(head(CNRM_1))
    structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000796599906001783, 0, 0, 0, 
    0, 0, 0, 0, 0, 0.000837936005501152, 0.000871552319509912, 
    0.00100709419004943, 0, 0, 0.0012105632950364, 0, 0, 0, 0, 
    0.00103714216752641, 0.00104333072151312, 0.000794459549629719, 
    0.00198828994745526, 0.00232027342913862, 0.00152433704387084, 
    0.00145669475130489, 0, 0, 0, 0.00106764166637498, 0.00133117261345192, 
    0.000751185736039872, 0.00205181592210355, 0.00235624992234934, 
    0.00160364560215041, 0.00225981611592611, 0, 0, 0, 0.00094873888615985, 
    0.00159345054110917, 0.000750502129892894, 0.00166613986487262, 
    0.00245039132047496, 0.00204705133350925, 0.00264872849452662, 
    0, 0, 0, 0.000704677797913744, 0.00158751407612522, 0.00105819696412664, 
    0.00112746366228874, 0.00220263084576204, 0.00300220982410644, 
    0.00268456275374276, 0, 0, 0, 0, 0.00112959733971154, 0.00153415586525737, 
    0.000503537889893361, 0.000948829835912542, 0.00221998566976762, 
    0.0031083088899198
    ), dim = c(10L, 20L), dimnames = list(c("1", "2", "3", "4", "5", 
    "6", "7", "8", "9", "10"), c("1", "2", "3", "4", "5", "6", "7", 
    "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
    "19", "20")))

    > dput(head(coords_df))
    structure(list(x = c(66.5, 67, 67.5, 68, 68.5, 69), y = c(66.5, 
    66.5, 66.5, 66.5, 66.5, 66.5)), row names = c(NA, 6L), class = "data.frame")
英文:

I'm trying to plot points on certain coordinates on a raster layer.

> head(coords_df)
x    y
1 66.5 66.5
2 67.0 66.5
3 67.5 66.5
4 68.0 66.5
5 68.5 66.5
6 69.0 66.5

Im trying to plot using the following

plot(CNRM_1)
points(coords_df, pch=16)

the raster is plotting but not the points. any help on where to fix this?

   > dput(head(CNRM_1))
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000796599906001783, 0, 
0, 0, 0, 0, 0, 0, 0, 0.000837936005501152, 0.000871552319509912, 
0.00100709419004943, 0, 0, 0.0012105632950364, 0, 0, 0, 0, 0.00103714216752641, 
0.00104333072151312, 0.000794459549629719, 0.00198828994745526, 
0.00232027342913862, 0.00152433704387084, 0.00145669475130489, 
0, 0, 0, 0.00106764166637498, 0.00133117261345192, 0.000751185736039872, 
0.00205181592210355, 0.00235624992234934, 0.00160364560215041, 
0.00225981611592611, 0, 0, 0, 0.00094873888615985, 0.00159345054110917, 
0.000750502129892894, 0.00166613986487262, 0.00245039132047496, 
0.00204705133350925, 0.00264872849452662, 0, 0, 0, 0.000704677797913744, 
0.00158751407612522, 0.00105819696412664, 0.00112746366228874, 
0.00220263084576204, 0.00300220982410644, 0.00268456275374276, 
0, 0, 0, 0, 0.00112959733971154, 0.00153415586525737, 0.000503537889893361, 
0.000948829835912542, 0.00221998566976762, 0.0031083088899198
), dim = c(10L, 20L), dimnames = list(c("1", "2", "3", "4", "5", 
"6", "7", "8", "9", "10"), c("1", "2", "3", "4", "5", "6", "7", 
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19", "20")))
> dput(head(coords_df))
structure(list(x = c(66.5, 67, 67.5, 68, 68.5, 69), y = c(66.5, 
66.5, 66.5, 66.5, 66.5, 66.5)), row.names = c(NA, 6L), class = "data.frame")

答案1

得分: 1

不确定 CNRM_1 的情节应该是什么样的,也许可以尝试 图像,然后添加

image(CNRM_1)

pp <- data.frame(x = c(0, 0.6), y = c(0.4, 0.8))
points(pp, pch = 16)

在绘图函数中无法绘制点。

英文:

Not sure how the plot is supposed to look like for CNRM_1, maybe try image, then add points:

image(CNRM_1)
pp &lt;- data.frame(x = c(0, 0.6), y = c(0.4, 0.8))
points(pp, pch = 16)

在绘图函数中无法绘制点。

答案2

得分: 0

The reason the points from coords_df don't show up is because the x- and y-axes are different between CRNM_1 and coords_df.

I agree that it's difficult to see what you want the final plot to look like, and image is likely the way to go. However, since you used plot(CNRM_1) in your original approach, to add the points from coords_df, you would need to add a new plot using par(new = TRUE).

plot(CNRM_1)
par(new = TRUE)
plot(coords_df, pch = 16, 
     axes = FALSE, 
     ylab = "", xlab = "")

在绘图函数中无法绘制点。

英文:

The reason the points from coords_df dont show up is because the x- and y-axes are different between CRNM_1 and coords_df.

I agree that it's difficult to see what you want the final plot to look like and image is likely the way to go. However, since you used plot(CNRM_1) in your original approach, to add the points from coords_df you would need to add a new plot using par(new = TRUE)

plot(CNRM_1)
par(new = TRUE)
plot(coords_df, pch = 16, 
axes = FALSE, 
ylab = &quot;&quot;, xlab = &quot;&quot;)

在绘图函数中无法绘制点。

huangapple
  • 本文由 发表于 2023年3月7日 18:01:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660478.html
匿名

发表评论

匿名网友

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

确定