【问题标题】:Adding text on scatter plots using xyplot for log-scale axis使用 xyplot 在散点图上添加文本作为对数刻度轴
【发布时间】:2014-08-16 18:18:14
【问题描述】:

当我尝试在对数尺度散点图的格中使用 panel.text(或 ltext)添加文本时遇到了这个问题。我知道对于正常情节,您会使用:

attach(mtcars) # using the mtcars as an example:

mytext<- paste("text here")


xyplot(mpg~wt, scales=list(cex=.8, col="red"),
       xlab="Weight", ylab="Miles per Gallon", 
       main="MGP vs Weight by Horse Power",
       panel=function(x, y, ...) {
         panel.xyplot(x, y, ...);
         ltext(4.5, 15, labels=mytext, cex=2)}
)

如果我对对数比例图执行相同操作,则不会显示文本。

xyplot(mpg~wt, scales=list(cex=.8, col="red",
                               x = list(log = T), y = list(log = T)),
       xlab="Weight", ylab="Miles per Gallon", 
       main="MGP vs Weight by Horse Power",
       panel=function(x, y, ...) {
         panel.xyplot(x, y, ...);
         ltext(4.5, 15, labels=mytext, cex=2)}
)

有什么建议吗?谢谢!

【问题讨论】:

  • 你能提供一个可重现的例子吗?人们会更容易帮助您解决问题。
  • 对不起,我上次没有把我的问题说清楚。现在这个例子应该做到了!谢谢 SimonG。

标签: r lattice scatter-plot


【解决方案1】:

您需要将 x 和 y 坐标转换为文本的对数刻度。

library(lattice)
xyplot(mpg~wt, mtcars, 
    scales=list(cex=.8, col="red", x = list(log = T), y = list(log = T)),
    xlab="Weight", ylab="Miles per Gallon", 
    main="MGP vs Weight by Horse Power",
    panel=function(x, y, ...) {
        panel.xyplot(x, y, ...);
        ltext(log10(4.5), log10(15), labels=mytext, cex=2)
    }
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-17
    • 2018-10-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多