首页 文章

自动确定图例的位置

提问于
浏览
3

您可以在大多数绘图程序中手动定位关键图例 . 例如,在gnuplot中使用 set key top right 完成 . 在ggplot2中,它完成like this .

是否有绘图库,脚本或简单算法自动定位图例,使其与图中的数据重叠最小?

我的意思是:假设我绘制了 y=x 行 . 在这种情况下,传奇的一个好地方是左上角或右下角 .

2 回答

  • 4

    试试这个,

    require(Hmisc)
    ?largest.empty
    

    R-help档案中还提出了其他讨论和功能

  • 6
    require(plotrix)
    
    ?emptyspace     # Find the largest empty space on a plot
    

    这是帮助页面中的示例:

    x<-rnorm(100)
     y<-rnorm(100)
     plot(x,y,main="Find the empty space",xlab="X",ylab="Y")
     es<-plotrix::emptyspace(x,y)
     # use a transparent background so that any overplotted points are shown
     plotrix::boxed.labels(es,labels="Here is the\nempty space",bg="transparent")
    

相关问题