使用 R plotly 更改 3d 图的标签
Change the labels of a 3d plot using R plotly
我在 R 中使用 plotly 创建了以下 3d 图。
library(plotly)
library(MASS)
mu_v=c(0.5,0.4,0.5,0.2)
sigma_m=matrix(data = c(1,0.5,0.7,0.4,0.5,1,0.8,0.9,0.7,0.8,1,0.5,0.4,0.9,0.5,1),nrow = 4,byrow = T)
data1=mvrnorm( 10000,mu = mu_v , Sigma = sigma_m )
data1=as.data.frame(data1)
colnames(data1)=c("X1","X2","X3","X4")
plot_ly(x=~X1, y=~X2, z=~X3, type="scatter3d", color=~(X4), mode="markers",data = data1
, marker = list(
size = 5,
opacity = 10)) %>% layout(plot_bgcolor = "#bababa")
有没有办法改变轴的标签和着色变量?还有我可以改变xy,yz和xz表面的背景并增加绘图区域吗?
更新
我尝试编辑图例并更改背景颜色如下:
plot_ly(x=~X1, y=~X2, z=~X3, type="scatter3d", color=~(X4), mode="markers",data = data1
, marker = list(
size = 5,
opacity = 10)) %>%
layout(scene = list(legend = list(title = "legend"),plot_bgcolor='#e5ecf6'))
但是没用
这里有一个选项可以解决您的前 2 个问题(更改 x/y/z 轴和颜色图例标题)。
plot_ly(
x = ~X1,
y = ~X2,
z = ~X3,
type = "scatter3d",
mode = "markers",
data = data1,
marker = list(
color = ~X4,
colorbar = list(title = "Legend"), # Change colour legend title
colorscale = "Blues", # Change colour palette
size = 5,
opacity = 10)) %>%
layout(
plot_bgcolor = "#bababa",
scene = list(
xaxis = list(title = "Axis 1"), # Change x/y/z axis title
yaxis = list(title = "Axis 2"),
zaxis = list(title = "Axis 3")))
我在 R 中使用 plotly 创建了以下 3d 图。
library(plotly)
library(MASS)
mu_v=c(0.5,0.4,0.5,0.2)
sigma_m=matrix(data = c(1,0.5,0.7,0.4,0.5,1,0.8,0.9,0.7,0.8,1,0.5,0.4,0.9,0.5,1),nrow = 4,byrow = T)
data1=mvrnorm( 10000,mu = mu_v , Sigma = sigma_m )
data1=as.data.frame(data1)
colnames(data1)=c("X1","X2","X3","X4")
plot_ly(x=~X1, y=~X2, z=~X3, type="scatter3d", color=~(X4), mode="markers",data = data1
, marker = list(
size = 5,
opacity = 10)) %>% layout(plot_bgcolor = "#bababa")
有没有办法改变轴的标签和着色变量?还有我可以改变xy,yz和xz表面的背景并增加绘图区域吗?
更新
我尝试编辑图例并更改背景颜色如下:
plot_ly(x=~X1, y=~X2, z=~X3, type="scatter3d", color=~(X4), mode="markers",data = data1
, marker = list(
size = 5,
opacity = 10)) %>%
layout(scene = list(legend = list(title = "legend"),plot_bgcolor='#e5ecf6'))
但是没用
这里有一个选项可以解决您的前 2 个问题(更改 x/y/z 轴和颜色图例标题)。
plot_ly(
x = ~X1,
y = ~X2,
z = ~X3,
type = "scatter3d",
mode = "markers",
data = data1,
marker = list(
color = ~X4,
colorbar = list(title = "Legend"), # Change colour legend title
colorscale = "Blues", # Change colour palette
size = 5,
opacity = 10)) %>%
layout(
plot_bgcolor = "#bababa",
scene = list(
xaxis = list(title = "Axis 1"), # Change x/y/z axis title
yaxis = list(title = "Axis 2"),
zaxis = list(title = "Axis 3")))