Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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,将Y轴标签替换为geom_平铺_R_Ggplot2 - Fatal编程技术网

R:ggplot2,将Y轴标签替换为geom_平铺

R:ggplot2,将Y轴标签替换为geom_平铺,r,ggplot2,R,Ggplot2,我成功地使用了中提供的代码,但是我无法用文本标签替换Y轴,这可能吗 library(reshape2) library(ggplot2) # Create dummy data set.seed(123) df <- data.frame( a = sample(1:5, 25, replace=TRUE), b = sample(1:5, 25, replace=TRUE), c = sample(1:5, 25, replace=TRUE) ) # Perform cl

我成功地使用了中提供的代码,但是我无法用文本标签替换Y轴,这可能吗

library(reshape2)
library(ggplot2)

# Create dummy data
set.seed(123)
df <- data.frame(
  a = sample(1:5, 25, replace=TRUE),
  b = sample(1:5, 25, replace=TRUE),
  c = sample(1:5, 25, replace=TRUE)
)

# Perform clustering
k <- kmeans(df, 3)

# Append id and cluster
dfc <- cbind(df, id=seq(nrow(df)), cluster=k$cluster)

# Add idsort, the id number ordered by cluster 
dfc$idsort <- dfc$id[order(dfc$cluster)]
dfc$idsort <- order(dfc$idsort)

# use reshape2::melt to create data.frame in long format
dfm <- melt(dfc, id.vars=c("id", "idsort"))

ggplot(dfm, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value))
library(重塑2)
图书馆(GG2)
#创建虚拟数据
种子集(123)

df您可以使用
scale\u y\u continuous()
设置
中断=
,然后提供
标签=
(例如,仅使用字母)。使用参数
expand=c(0,0)
inside
scale.
可以删除绘图中的灰色区域

ggplot(dfm, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value))+
  scale_x_discrete(expand=c(0,0))+
  scale_y_continuous(expand=c(0,0),breaks=1:25,labels=letters[1:25])

您可以使用
scale\u y\u continuous()
设置
中断=
,然后提供
标签=
(例如,仅使用字母)。使用参数
expand=c(0,0)
inside
scale.
可以删除绘图中的灰色区域

ggplot(dfm, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value))+
  scale_x_discrete(expand=c(0,0))+
  scale_y_continuous(expand=c(0,0),breaks=1:25,labels=letters[1:25])