我有一个包含三个变量的数据框,
location
,
price
和
varname
.
我想使用ggplot2
geom_tile
制作各种各样的热图。这个图看起来几乎像一个条形图,但我更喜欢
geom_瓷砖
因为我喜欢在绘图上分配相同数量的物理空间,无论大小。我的代码几乎把我带到了那里。
第一个问题是我无法格式化绘图,因此无法去掉伪条左右两侧的所有空白。第二个问题是我无法删除
Price
下面的故事情节,因为我想
价格
仅在绘图上方的图例中显示。
谢谢你的帮助!
起点(
df
):
df <- data.frame(location=c("AZ","MO","ID","MI"),price=c(1380.45677,1745.1245,12.45652,1630.65341),varname=c("price","price","price","price"))
当前代码:
library(ggplot2)
ggplot(df, aes(varname,location, width=.2)) + geom_tile(aes(fill = price),colour = "white") + geom_text(aes(label = round(price, 3))) +
scale_fill_gradient(low = "ivory1", high = "green") +
theme_classic() + labs(x = "", y = "") + theme(legend.position = "none") + ggtitle("Price")