Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.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 ggplot2直方图比例\填充\梯度不适用于连续变量_R - Fatal编程技术网

R ggplot2直方图比例\填充\梯度不适用于连续变量

R ggplot2直方图比例\填充\梯度不适用于连续变量,r,R,我很难使用ggplot2直方图使连续变量在scale_fill_梯度上工作。(我有办法将变量转换为因子,使用scale_fill_manual并手动设置,因此我知道我的库和一般ggplot结构是正确的。这是我的第一个示例。)我已经根据帮助文本完成了所有操作,但在第二个示例中,它似乎根本无法识别我的填充 > str(data) 'data.frame': 506 obs. of 9 variables: $ value_A : int 250000 2

我很难使用ggplot2直方图使连续变量在scale_fill_梯度上工作。(我有办法将变量转换为因子,使用scale_fill_manual并手动设置,因此我知道我的库和一般ggplot结构是正确的。这是我的第一个示例。)我已经根据帮助文本完成了所有操作,但在第二个示例中,它似乎根本无法识别我的填充

 > str(data)

'data.frame':   506 obs. of  9 variables:
 $ value_A              : int  250000 219000 358000 340000 364000 295000 
 $ factor_B             : Factor w/ 6 levels "4","5","6","7",..: 4 3 4 4 4 3 
 $ numeric_C             : num  15.3 17.8 17.8 18.7 18
这很好(它是在一个因子变量上):

这不起作用,它用灰色填充所有栏,也没有任何类型的图例:(这是数值变量)

试试这个:

ggplot(data, aes(value, fill = numeric_C)) +
  geom_histogram(aes(fill = ..count..), binwidth = 30000)  + # ...
  scale_fill_gradient("some Ratio", low = "#9db5bf", high = "#235970")

我想我也有同样的问题,你解决过这个问题吗?
    ggplot(data, aes(value, fill = numeric_C)) +
  geom_histogram(binwidth = 30000)  + ...
  scale_fill_gradient("some Ratio", low = "#9db5bf", high = "#235970")
ggplot(data, aes(value, fill = numeric_C)) +
  geom_histogram(aes(fill = ..count..), binwidth = 30000)  + # ...
  scale_fill_gradient("some Ratio", low = "#9db5bf", high = "#235970")