我在 R 中使用 plotly 创建了以下 3d 散点图。 为此,我使用了以下代码 数据集 Txy,仅包含每个标记的 x、y、z 坐标和每个坐标点的 0-1.5 之间的值(在名为 vectorM 的列中)
figfactor<- plot_ly(setTxy, x=~xplot,y=~yplot*-1,z=(~zplot*-1),
type="scatter3d",mode="markers",
marker=list(color=~vectorM,
colorscale=c("rgb(244, 244, 244)","rgb(65, 65, 65)"),
showscale=TRUE,
line=list(width=2,color='DarkSlateGrey')))
figfactor <- figfactor %>% add_markers()
figfactor <- figfactor %>% layout(scene = list(xaxis = list(title = 'x-value [mm]'),
yaxis = list(title = 'y-value [mm]'),
zaxis = list(title = 'z-value [mm]')),
annotations = list(
x = 1.06,
y = 1.03,
text = 'factor',
xref = 'paper',
yref = 'paper',
showarrow = FALSE
))
figfactor
我以为我把所有的颜色都改成灰色了,但是剧情里还是有颜色的。 我怎样才能改变这个?进一步: - 为什么缩放比例不是灰色的;我该如何创建它? - 我怎样才能在右边的刻度上方勾勒出“因素” - 为什么我有“迹线 0”和“迹线 1”?
我怎样才能在这个图中画两个圆,要么通过绘制到图形中,要么通过使用圆的公式?
谢谢
最佳答案
来自文档 scatter-marker-color问题是颜色以错误的格式给出。注意下面加粗的部分
Sets the colorscale. Has an effect only if in
marker.line.color
is set to a numerical array. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required. For example,[[0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']]
. To control the bounds of the colorscale in color space, usemarker.line.cmin
andmarker.line.cmax
. Alternatively,colorscale
may be a palette name string of the following list:
- Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis, Cividis.
在 R
中,数组要么使用 array
创建,要么作为列表(或向量列表)的 list
创建。因此,我们可以通过两种方式获得全灰色着色:
- 设置
colourscale = 'Greys'
- 将您的向量重新映射到向量列表。
以 mtcars
数据为例,这可以按照以下方式完成
data(mtcars)
library(plotly)
plot_ly(mtcars, x = ~hp, y = ~cyl, z = ~mpg,
type = 'scatter3d', mode = 'markers',
marker = list(color = ~ hp,
# Use either a named palette in the above list:
#colorscale = 'Greys',
# Or use a list of vector scales.
colorscale = list(c(0, rgb(55, 55, 55, max = 255)),
c(1, rgb(244, 244, 244, max = 255))),
showscale = TRUE))
请注意,line
参数是不必要的,除非您特别想在点之间添加线,并且列表的顺序很重要(例如。c (1, ...)
应该总是在 c(0, ...)
之后。
关于r - 在 plotly scatter3D 中改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63251802/