R 使绘图的yaxis标题水平
我试图在垂直方向上组合R 使绘图的yaxis标题水平,r,plotly,title,subplot,R,Plotly,Title,Subplot,我试图在垂直方向上组合Rplotly绘图列表,但由于每个单独绘图的y轴标题是水平的,因此组合的绘图结果很混乱 下面是我的例子: 数据: 然后,使用以下方法组合它们: subplot(plot.list,nrows=length(plot.list),shareX=T,shareY=T,titleX=T,titleY=T) 给出: 如何在绘图中旋转每个绘图的y轴标题。请将列表设置为水平而不是垂直?如果我理解正确,则无法按照本机实现 但是,正如链接所建议的,尝试使用注释 下面是一个可能的方法-
R
plotly
绘图列表,但由于每个单独绘图的y轴标题是水平的,因此组合的绘图结果很混乱
下面是我的例子:
数据:
然后,使用以下方法组合它们:
subplot(plot.list,nrows=length(plot.list),shareX=T,shareY=T,titleX=T,titleY=T)
给出:
如何在
绘图中旋转每个绘图的y轴标题。请将
列表设置为水平而不是垂直?如果我理解正确,则无法按照本机实现
但是,正如链接所建议的,尝试使用注释
下面是一个可能的方法-
set.seed(1)
df <- data.frame(cluster=unlist(lapply(letters[1:10],function(i) rep(paste0("cluster:",i),200))),
group=rep(c(rep("A",100),rep("B",100)),10),val=rnorm(2000))
df$group <- factor(df$group,levels=c("A","B"))
library(plotly)
plot.list <- lapply(unique(df$cluster),function(i){
density.df <- do.call(rbind,lapply(c("A","B"),function(b){
dens <- density(dplyr::filter(df,cluster == i,group == b)$val,adjust=1)
return(data.frame(x=dens$x,y=dens$y,group=b,stringsAsFactors=F))
}))
density.df$group <- factor(density.df$group,levels=c("A","B"))
if(i == unique(df$cluster)[1]){
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=T) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F),legend=list(orientation="h",xanchor="center",x=0,y=1)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
} else {
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=F) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
}
return(cluster.plot)
})
subplot(plot.list,nrows=length(plot.list),shareX=T,shareY=T,titleX=T,titleY=T)
set.seed(1)
df如果我理解正确,这无法通过本机实现
但是,正如链接所建议的,尝试使用注释
下面是一个可能的方法-
set.seed(1)
df <- data.frame(cluster=unlist(lapply(letters[1:10],function(i) rep(paste0("cluster:",i),200))),
group=rep(c(rep("A",100),rep("B",100)),10),val=rnorm(2000))
df$group <- factor(df$group,levels=c("A","B"))
library(plotly)
plot.list <- lapply(unique(df$cluster),function(i){
density.df <- do.call(rbind,lapply(c("A","B"),function(b){
dens <- density(dplyr::filter(df,cluster == i,group == b)$val,adjust=1)
return(data.frame(x=dens$x,y=dens$y,group=b,stringsAsFactors=F))
}))
density.df$group <- factor(density.df$group,levels=c("A","B"))
if(i == unique(df$cluster)[1]){
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=T) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F),legend=list(orientation="h",xanchor="center",x=0,y=1)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
} else {
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=F) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
}
return(cluster.plot)
})
subplot(plot.list,nrows=length(plot.list),shareX=T,shareY=T,titleX=T,titleY=T)
set.seed(1)
df
set.seed(1)
df <- data.frame(cluster=unlist(lapply(letters[1:10],function(i) rep(paste0("cluster:",i),200))),
group=rep(c(rep("A",100),rep("B",100)),10),val=rnorm(2000))
df$group <- factor(df$group,levels=c("A","B"))
library(plotly)
plot.list <- lapply(unique(df$cluster),function(i){
density.df <- do.call(rbind,lapply(c("A","B"),function(b){
dens <- density(dplyr::filter(df,cluster == i,group == b)$val,adjust=1)
return(data.frame(x=dens$x,y=dens$y,group=b,stringsAsFactors=F))
}))
density.df$group <- factor(density.df$group,levels=c("A","B"))
if(i == unique(df$cluster)[1]){
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=T) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F),legend=list(orientation="h",xanchor="center",x=0,y=1)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
} else {
cluster.plot <- plot_ly(x=~density.df$x,y=~density.df$y,type='scatter',mode='lines',color=~density.df$group,line=list(width=3),showlegend=F) %>%
layout(xaxis=list(title="Val",zeroline=F),yaxis=list(title = '', zeroline=F,showticklabels=F)) %>%
add_annotations(text = i, x = -0.1, xref = 'paper', y = 0.5, yref = 'paper', showarrow = FALSE)
}
return(cluster.plot)
})
subplot(plot.list,nrows=length(plot.list),shareX=T,shareY=T,titleX=T,titleY=T)