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

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

points not plotting in plot function

问题

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

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

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

  1. plot(CNRM_1)
  2. points(coords_df, pch=16)

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

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

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

Im trying to plot using the following

  1. plot(CNRM_1)
  2. points(coords_df, pch=16)

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

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

答案1

得分: 1

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

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

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

英文:

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

  1. image(CNRM_1)
  2. pp &lt;- data.frame(x = c(0, 0.6), y = c(0.4, 0.8))
  3. 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).

  1. plot(CNRM_1)
  2. par(new = TRUE)
  3. plot(coords_df, pch = 16,
  4. axes = FALSE,
  5. 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)

  1. plot(CNRM_1)
  2. par(new = TRUE)
  3. plot(coords_df, pch = 16,
  4. axes = FALSE,
  5. 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:

确定