Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 ggplot&x2B;几何点+;基于大小和颜色的图例_R_Ggplot2_Legend_Legend Properties - Fatal编程技术网

R ggplot&x2B;几何点+;基于大小和颜色的图例

R ggplot&x2B;几何点+;基于大小和颜色的图例,r,ggplot2,legend,legend-properties,R,Ggplot2,Legend,Legend Properties,使用geom_point时,是否有办法在图例中显示尺寸和颜色 library(ggplot2) cons2 <- data.frame( value_date = as.Date(c('2013-04-30', '2013-04-30', '2013-06-13', '2013-06-13')), ticker = c('AAPL','FTW','AAPL','FTW'), discount = c(0.34,0.10,0.25,0.20), b = c(0.40,0.5

使用
geom_point
时,是否有办法在图例中显示尺寸和颜色

library(ggplot2)
cons2 <- data.frame(
  value_date  = as.Date(c('2013-04-30', '2013-04-30', '2013-06-13', '2013-06-13')),
  ticker = c('AAPL','FTW','AAPL','FTW'),
  discount = c(0.34,0.10,0.25,0.20),
  b = c(0.40,0.55,.60,0.90),
  yield = c(0.08,0.04, 0.06,0.03)
)

p <- ggplot(cons2)
p <- p + geom_point(aes(yield,b, size = discount, color=value_date))
p
库(ggplot2)

cons2ggplot2不知道如何处理Date类。尝试:

color=factor(value_date)

相反。

出于某种原因,ggplot2无法自动确定它需要日期框。试着明确地告诉它:

ggplot(cons2) +
  geom_point(aes(yield, b, size = discount, color = value_date)) +
  scale_colour_gradient(trans = "date")

谢谢你解决了我的问题。有没有办法只在图例中显示日期而不打折?@BørgeKlungerbo是的,
p+guides(size=“none”)
。非常感谢您的快速回答!