gpt4 book ai didi

r - 如何强制 x 轴刻度线出现在热图中条形图的末尾?

转载 作者:行者123 更新时间:2023-12-04 10:44:48 25 4
gpt4 key购买 nike

我使用 ggplot2 创建了一个简单的热图,但我需要强制 x 轴刻度线出现在我的 x 变量的末尾,而不是它的中心。例如,我希望 1 出现在 1.5 现在所在的位置。我相信在 Base R 中完成的热图可以做到这一点。

library(car) #initialize libraries
library(ggplot2) #initialize libraries
library(reshape)

df=read.table(text= "x y fill
1 1 B
2 1 A
3 1 B
1 2 A
2 2 C
3 2 A
", header=TRUE, sep="" )

#plot data
qplot(x=x, y=y,
fill=fill,
data=df,
geom="tile")+
scale_x_continuous(breaks=seq(1:3) )

enter image description here

我们的想法是创建一个简单的热图,如下所示: enter image description here

此图中的刻度线位于条形的末端而不是它们的中心

最佳答案

这个呢?

object = qplot(x=x, y=y, 
fill=fill,
data=df,
geom="tile")+
scale_x_continuous(breaks=seq(1:3))

object + scale_x_continuous(breaks=seq(.5,3.5,1), labels=0:3)

enter image description here

关于r - 如何强制 x 轴刻度线出现在热图中条形图的末尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10710463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com