【发布时间】:2020-07-27 07:17:10
【问题描述】:
单位库简化了单位的使用。据我所知,使用单位绘图适用于基本图,但不适用于 ggplot。有什么建议吗?
library(units)
# Take cars data frame: stopping dist (ft) vs speed (mph)
plot(cars)
# units + base plot
Distance = set_units(cars$dist, ft)
Speed = set_units(cars$speed, mph)
plot(x=Speed, y=Distance) #Clean
# units + ggplot
library(ggplot2)
df = cars
df$Disance = set_units(df$dist, ft)
df$Speed = set_units(df$speed, mph)
qplot(x=Speed, y=Distance, data=df)
# Error in Ops.units(x, range[1]) :
# both operands of the expression should be "units" objects
【问题讨论】:
标签: r ggplot2 units-of-measurement