简体   繁体   English

用xy.coords在r中绘制坐标

[英]plotting coordinates in r with xy.coords

I want to plot a series of coordinates in R (which I am just beginning to learn about) and found xy.coords as a tool to do so. 我想在R中绘制一系列坐标(我才刚刚开始学习),并找到xy.coords作为实现此目的的工具。 however, xy.coords fails to correctly interpret the data I want to feed to it. 但是,xy.coords无法正确解释我要提供给它的数据。

i imported the csv file with the data with 我用数据导入了csv文件

> objectname <- read.csv("./file", header=TRUE, sep=",")

showing the data in resulting from that directly looks like: 直接显示由此产生的数据看起来像:

> chances1617$location_y
[1] -             33.0          76.0          44.0          42.0         
[6] 20.0          54.0          16.0          67.0          42.0         
[11] 16.0          44.0          31.0          17.0          90.0         
[16] 27.0          123.0         28.0          121.0         1.0   
...

> chances1617$location_x
[1] -              33.0           -36.0          -12.0         
[5] 22.0           2.0            -22.0          -16.0         
[9] -21.0          11.0           2.0            0.0           
[13] 32.0           -7.0           81.0           -17.0         
[17] -89.0          9.0            92.0           -136.0      
...

whereas xy.coords understands this as 而xy.coords将其理解为

> xy.coords(chances1617$location_x, chances1617$location_y)
$y
[1]   1 122 189 142 139  90 157  73 176 139  73 142 119  77 211 109  35 112
[19]  33   3 211 150  73  85   6 140 189 196 140 202 168 122 147  22 150 150 
...
$x
[1]   1 235  73  16 218 211  41  27  39 184 211 169 233 135 333  29 158 343
[19] 346  23  31 204 192  33 297 227 126  58 202   4  78 235  26 330 199 192

What may be going wrong there? 那里可能出了什么问题? Is the data I want to process with xz.coords in a wrong format, or am i using it wrong, or is it the wrong tool? 我要使用xz.coords处理的数据格式错误,还是我使用的数据错误,还是工具错误?

It looks like your data chances1617$location_x and chances1617$location_y are factors. 看来您的数据chances1617$location_xchances1617$location_y是因素。 Try converting them to numeric data by eg 尝试通过例如将它们转换为数字数据

xy.coords(as.numeric(as.character(chances1617$location_x)),
          as.numeric(as.character(chances1617$location_y)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xy.coords中的R错误 - R error in xy.coords R使用PerformanceAnalytics包绘制“ xy.coords(x,y)中的错误” - R plotting “Error in xy.coords(x, y)” using PerformanceAnalytics package R 中的逻辑回归使用 glm() 在绘图时在 xy.coords 中产生错误 - Logistic regression in R using glm() produces error in xy.coords when plotting R语言xy.coords(x,y)中的错误 - R language Error in xy.coords(x, y) xy.coords处理NA中的错误 - Error in xy.coords dealing with NAs xy.coords脚本与控制台中的错误 - Error in xy.coords Script vs Console xy.coords(x,y)中的错误:&#39;x&#39;和&#39;y&#39;的长度不同图表.PerformanceSummary R XTS - Error in xy.coords(x, y) : 'x' and 'y' lengths differ charts.PerformanceSummary R XTS R:xy.coords(x,y,xlabel,ylabel,log)中的错误:&#39;x&#39;和&#39;y&#39;的长度不同 - R: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ R:xy.coords 中的错误(x,y,xlabel,ylabel,log):“x”是一个列表,但没有组件“x”和“y” - R: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y' 绘制折线图,​​xy.coords中的错误(x,y,xlabel,ylabel,log):&#39;x&#39;和&#39;y&#39;长度不同 - Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM