【问题标题】:Showing axes in bitmap plot in R and scaling bitmap plot在 R 中的位图中显示轴并缩放位图
【发布时间】:2017-04-09 16:03:35
【问题描述】:

我正在尝试将轴添加到 R 中的位图图中。但它没有显示这些轴。我正在使用带有 R v3.3.0 的 OS X 10.10

set.seed(0)

#Sample matrix
bitmap<-matrix(rnorm(150000,mean=1:500),nrow = 300, ncol = 500)

image(bitmap,col = RColorBrewer::brewer.pal(9,"Greys"), axes=FALSE, 
  useRaster = TRUE)

axis(1,at = seq(from=1000,to = 10000,length.out = 19), 
  labels = seq(from=1000,to = 10000,length.out = 19))

axis(2,at = seq(from=0,to = 100,length.out = 11),
  labels = seq(from=0,to = 100,length.out = 11))
  1. 如何在 R 中以所需范围显示这些所需轴?

  2. 如何在 R 中以像素或某个长度单位指定绘制位图的大小?

  3. 如何独立缩放位图的宽度和高度?

  4. 还有其他 R 包可以让我以更好的方式处理这些参数吗?

【问题讨论】:

    标签: r plot graphics


    【解决方案1】:

    image() 将两个轴都缩放为 1。您只需调整您的 at= 值

    axis(1,at = seq(from=1000,to = 10000,length.out = 19)/10000, 
      labels = seq(from=1000,to = 10000,length.out = 19))
    
    axis(2,at = seq(from=0,to = 100,length.out = 11)/100,
      labels = seq(from=0,to = 100,length.out = 11))
    

    渲染图像的大小取决于您当前的图形设备。您不能以像素为单位明确控制绘图区域的大小,只能控制整体绘图大小(包括轴和所有内容)。 R 中的图形往往会根据窗口大小而增长和缩小。如果您愿意,可以在plot() 调用中使用asp=1 来修复纵横比。

    如果您需要像素级控制,您可能需要使用其他程序进行绘图。

    【讨论】:

    • 谢谢!您的回复已经回答了我的问题。我不知道 at 的范围是 0 到 1。
    猜你喜欢
    • 2015-12-21
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多