Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用几何平铺和比例\梯度\手动绘制离散值_R_Ggplot2 - Fatal编程技术网

R 使用几何平铺和比例\梯度\手动绘制离散值

R 使用几何平铺和比例\梯度\手动绘制离散值,r,ggplot2,R,Ggplot2,我有一个数据帧的以下部分,它比这个大得多: x y A 1 1 0.1176405 2 2 0.1176405 3 3 0.1219375 4 4 0.09942536 5 5 0.1031696 6 6 0.1384145 我尝试使用ggplot2进行绘图: p <- ggplot(df, aes(x,y)) + geom_tile(aes(fill=A))+

我有一个数据帧的以下部分,它比这个大得多:

    x   y       A    
    1   1  0.1176405
    2   2  0.1176405
    3   3  0.1219375
    4   4 0.09942536
    5   5  0.1031696
    6   6  0.1384145
我尝试使用ggplot2进行绘图:

p <- ggplot(df, aes(x,y)) + 
  geom_tile(aes(fill=A))+ 
  scale_fill_gradient(low = "black", high = "red")
当我尝试在绘图中使用.numeric(A)时,它确实起作用,但绘图中的值看起来很奇怪,并且不显示我的值

这是
str()
的输出:


那么我应该怎么做才能使这个绘图正常工作呢?

看起来像是数据框中的
A
是一个因子,需要转换为数值。尝试:

df$A <- as.numeric(as.character(df$A))

参见8.2.1

你能在你的数据上显示
str()
的输出吗?@joran:我把它添加到问题中,你能告诉我们你得到了什么吗?@RomanLuštrik:我没有得到结果,只是问题中发现的错误
'data.frame':   289 obs. of  3 variables:
 $ x: num  1 2 3 4 5 ...
 $ y: num  1 2 3 4 5 6 7 8 9 10 ...
 $ A: Factor w/ 181 levels "0.1176405","0.1219375",..: 1 1 2 3 4 4 5 6 7 8 ...
df$A <- as.numeric(as.character(df$A))
as.numeric(factor(50:55))
[1] 1 2 3 4 5 6