【问题标题】:Label scatterplot points with derived axis in base R在基础 R 中使用派生轴标记散点图点
【发布时间】:2021-11-13 13:08:09
【问题描述】:

这是我的数据的样子:

> dput(head(GDP_NUTS2,5))

structure(list(Regiao = c("N", "Ag", "C", "AML", "Al"), t2000 = c(10054.60679, 
13045.59069, 10621.51789, 18104.36306, 11585.29235), t2001 = c(10652.46712, 
13920.41552, 11101.08412, 18865.55149, 12014.61685), t2002 = c(11001.34917, 
14612.37052, 11507.36163, 19812.29293, 12411.44835), t2003 = c(11031.7278, 
15137.89461, 11884.96687, 20165.68892, 12889.20298), t2004 = c(11354.02317, 
15479.68985, 12364.05053, 21068.05117, 13448.52482), t2005 = c(11875.44359, 
16237.49791, 12754.40299, 21829.31373, 13867.5055), t2006 = c(12439.6426, 
17046.29326, 13378.47797, 22714.25829, 14767.48968), t2007 = c(13229.02402, 
17981.40383, 14044.39707, 23847.44923, 15362.11238), t2008 = c(13579.51144, 
18226.74178, 14091.85326, 24347.83971, 15335.54822), t2009 = c(13243.19054, 
17038.45595, 13974.46502, 23794.44899, 14836.93236), t2010 = c(13677.38358, 
16976.83391, 14284.14565, 24119.66719, 15489.72008), t2011 = c(13491.68626, 
16347.69468, 14011.54637, 23503.1765, 15200.84829), t2012 = c(13111.6173, 
16059.51047, 13623.68635, 22118.01701, 14510.73391), t2013 = c(13473.68717, 
16301.87448, 13919.18355, 22337.24739, 14628.8829), t2014 = c(13935.07757, 
16974.57715, 14220.1043, 22491.62875, 15021.05459), t2015 = c(14570.33755, 
17851.78088, 14983.95312, 23101.89351, 16297.81693), t2016 = c(15283.33044, 
19251.57661, 15620.77307, 23800.20038, 16737.39734), t2017 = c(16083.53849, 
20893.19975, 16410.11278, 24938.22636, 17888.34779), t2018 = c(17031.94867, 
22131.96942, 17242.70015, 25974.24055, 18396.58684), t2019 = c(17712.44223, 
23145.30242, 18045.54697, 26970.71178, 19006.1632)), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))

为了绘制 beta 收敛图,我使用了这个预制代码:

rca(GDP_NUTS2$t2000, 2000, GDP_NUTS2[3:21], 2019,  
    conditions=NULL, beta.plot=TRUE, beta.plotLine=TRUE, 
    beta.plotX="Ln (initial GDP p.c.)", beta.plotY="Ln (av. growth GDP p.c.)",
    beta.plotTitle="Beta convergence of Portuguese regions 2000-2019")

由于轴来自包装函数rca,而不是直接来自数据集,我不知道如何用行名标记散点图点。我看到的所有示例的代码图结构都完全不同。

任何帮助将不胜感激。

【问题讨论】:

  • 函数rca来自包{REAT}
  • 对,没错,忘了说
  • "用列名标记散点图"到底是什么意思?我只用你的代码得到一个情节。
  • 我将编辑我的问题以使其更清楚。我的意思是用行名而不是​​列名来标记散点图的点。我的错,对不起。
  • 我认为您不能在rca 中添加点标签,该功能似乎不允许这样做。也许您可以将rca 结果分配给一个对象,然后使用text 在现有绘图上添加标签?我试过,但在执行上面的rca 代码时出错,说:Error in is.finite(y) : default method not implemented for type 'list' In addition: Warning message: Only last time period is regarded.

标签: r label scatter-plot


【解决方案1】:

您没有提供足够的数据来运行您的代码,因此我将使用 rca 手册页上的示例中修改过的数据集。

library(REAT)
data (G.counties.gdp)   # GDP for German counties
Example <- G.counties.gdp[1:50, ]     # Just use the first 50 rows
out <- rca (Example$gdppc2010, 2010, Example$gdppc2011, 2011, 
       conditions = NULL, beta.plot = TRUE)
x <- out$betaconv$regdata$ln_initial
y <- out$betaconv$regdata$ln_growth
text(x, y, 1:50, pos=3, cex=.8)

轴的数据存储在您运行函数时返回的对象中(如果您分配了它)。这是情节:

【讨论】:

    猜你喜欢
    • 2021-08-16
    • 1970-01-01
    • 2014-01-25
    • 2012-03-18
    • 2013-10-31
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多