R plotly极坐标图简单定制
R plotly polar chart simple customizing
嗨 R 和情节专家,
我最近在尝试 plotly
。
这是我简单的最小设计代码:
library(plotly)
df <- data.frame(
r = c(0,1,2,2,1.5,3, 1, 2, 3, 4, 5, 6),
theta = c(0,45,90,315, 180, 270, 10, 40, 70, 100, 130, 160),
group = c('R', 'B', 'G', 'R', 'G', 'B', 'R', 'B', 'G', 'R', 'G', 'B'),
size = c(1, 2, 3, 10, 20, 9, 2, 4, 6, 8, 10, 12)
)
colors_map <- c("blue", "green", "red")
p <- plot_ly(
df,
type = 'scatterpolar',
r = ~r,
theta = ~theta,
color = ~group,
colors = colors_map, #Provide a color mapped vector
size = ~size,
sizes = c(100,200), #Provide a range of size.
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
mode = 'markers',
hoverinfo="text",
marker = list(symbol = 'circle', line = list(width = 2, color = 'lightgrey'))
)%>%
layout(title = 'SAMPLE TITLE',
showlegend = TRUE,
polar = list(
#hole = 0.5,
radialaxis = list(
tickfont = list(
size = 20,
color = "blue"
),
visible = TRUE,
tickcolor = toRGB("red"),
ticks = "outside",
#ticklen = 15,
#tickwidth = 20,
range = c(0, max(df$r)),
rangemode = "tozero",
angle = 90,
tickangle = 90,
#gridcolor = '#FFF', #color of grid lines
categoryorder = "array",
categoryarray = c("GroupA", "GroupB", "GroupC", "GroupD") #Not working
),
angularaxis = list(
tickfont = list(
size = 12
),
rotation = 90,
direction = 'clockwise' ,
categoryarray = c("A", "B", "C", "D") #Not working
)
)
)
ggplotly(p)
绘制的图表是:
我尝试了一些基于文档的东西,但无法实现。
以下是我未能呈现的项目[其中一些已解决并发布在答案中]:
[已解决] 根据点所属的组显示点的颜色。如果它属于 R
组,则颜色应为红色,如果 B
则为蓝色,如果 G
则为绿色。
[已解决]极坐标图中显示的点的大小很小,有没有办法可以放大它或给出一个大小范围?
[已解决]在每个点的中间,我想显示一个text/number,假设我想在每个点 的中心显示 size
值。我该怎么做?
删除基于角度的 angular 轴标签 并想将我的 自定义标签 作为 A
、B
、C
、D
分别为 45 度、135 度、225 度和 315 度。
[已解决] 在极坐标图外的垂直线上显示径向轴标签,而不是它是怎么回事出现在图表内。它应该在垂直规则形式的图表之外,我的自定义标签让我们说 GroupA
、GroupB
、GroupC
、GroupD
.
[已解决] 使 鼠标悬停工具提示 放大并在其中显示更多信息。例如,现在,group
信息显示在工具提示的外面,它应该在行内。正在从工具提示中删除 theta
。
如何在同心圆上填充灰色并写上文字?对于 ggplot
,我使用图表底部的 geom_rect
然后 coord_polar
实现了它,但这种方法在 polar chart
和 plotly
中不起作用。还有其他方法吗?
我知道这对于 plotly
专家来说可能是基本的事情,但自从过去 4 小时以来我一直在努力使事情变得混乱。
我想要类似下面的东西:
我敢肯定,这个问题在帮助初学者定制极地图表视觉效果方面会有很大帮助,因为没有在线帮助可用,因此需要解决这个问题。
感谢任何帮助。
到目前为止,我能够解决 SOLVED 项。
R剧情代码:
library(plotly)
df <- data.frame(
r = c(0,1,2,2,1.5,3, 1, 2, 3, 4, 5, 6),
theta = c(0,45,90,315, 180, 270, 10, 40, 70, 100, 130, 160),
group = c('R', 'B', 'G', 'R', 'G', 'B', 'R', 'B', 'G', 'R', 'G', 'B'),
size = c(1, 2, 3, 10, 20, 9, 2, 4, 6, 8, 10, 12)
)
colors_map <- c("blue", "green", "red")
p <- plot_ly(
df,
type = 'scatterpolar',
r = ~r,
theta = ~theta,
color = ~group,
colors = colors_map, #Provide a color mapped vector
size = ~size,
sizes = c(100,200), #Provide a range of size.
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
mode = 'markers',
hoverinfo="text",
marker = list(symbol = 'circle', line = list(width = 2, color = 'lightgrey'))
)%>%
layout(title = 'SAMPLE TITLE',
showlegend = TRUE,
polar = list(
#hole = 0.5,
radialaxis = list(
tickfont = list(
size = 20,
color = "blue"
),
visible = TRUE,
tickcolor = toRGB("red"),
ticks = "outside",
#ticklen = 15,
#tickwidth = 20,
range = c(0, max(df$r)),
rangemode = "tozero",
angle = 90,
tickangle = 90,
tickmode="array",
tickvals = c(0, 1, 2, 3, 4, 5, 6, 7),
ticktext = c('', "One", "Two", "Three", "Four", "Five", "Six", "Seven")
#gridcolor = '#FFF', #color of grid lines
#categoryorder = "array",
#categoryarray = c("GroupA", "GroupB", "GroupC", "GroupD") #Not working
),
angularaxis = list(
tickfont = list(
size = 12
),
rotation = 90,
direction = 'clockwise' ,
categoryarray = c("A", "B", "C", "D") #Not working
)
)
)%>%
add_trace(
r = ~r,
theta = ~theta,
mode = "text",
text = ~size,
textfont = list(color = '#000000', size = 12)
) %>%
add_trace(
r = ~r,
theta = ~theta,
mode = "marker",
opacity = 0.5,
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
hoverinfo = "text"
)
ggplotly(p)
图表:
嗨 R 和情节专家,
我最近在尝试 plotly
。
这是我简单的最小设计代码:
library(plotly)
df <- data.frame(
r = c(0,1,2,2,1.5,3, 1, 2, 3, 4, 5, 6),
theta = c(0,45,90,315, 180, 270, 10, 40, 70, 100, 130, 160),
group = c('R', 'B', 'G', 'R', 'G', 'B', 'R', 'B', 'G', 'R', 'G', 'B'),
size = c(1, 2, 3, 10, 20, 9, 2, 4, 6, 8, 10, 12)
)
colors_map <- c("blue", "green", "red")
p <- plot_ly(
df,
type = 'scatterpolar',
r = ~r,
theta = ~theta,
color = ~group,
colors = colors_map, #Provide a color mapped vector
size = ~size,
sizes = c(100,200), #Provide a range of size.
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
mode = 'markers',
hoverinfo="text",
marker = list(symbol = 'circle', line = list(width = 2, color = 'lightgrey'))
)%>%
layout(title = 'SAMPLE TITLE',
showlegend = TRUE,
polar = list(
#hole = 0.5,
radialaxis = list(
tickfont = list(
size = 20,
color = "blue"
),
visible = TRUE,
tickcolor = toRGB("red"),
ticks = "outside",
#ticklen = 15,
#tickwidth = 20,
range = c(0, max(df$r)),
rangemode = "tozero",
angle = 90,
tickangle = 90,
#gridcolor = '#FFF', #color of grid lines
categoryorder = "array",
categoryarray = c("GroupA", "GroupB", "GroupC", "GroupD") #Not working
),
angularaxis = list(
tickfont = list(
size = 12
),
rotation = 90,
direction = 'clockwise' ,
categoryarray = c("A", "B", "C", "D") #Not working
)
)
)
ggplotly(p)
绘制的图表是:
我尝试了一些基于文档的东西,但无法实现。 以下是我未能呈现的项目[其中一些已解决并发布在答案中]:
[已解决] 根据点所属的组显示点的颜色。如果它属于
R
组,则颜色应为红色,如果B
则为蓝色,如果G
则为绿色。[已解决]极坐标图中显示的点的大小很小,有没有办法可以放大它或给出一个大小范围?
[已解决]在每个点的中间,我想显示一个text/number,假设我想在每个点 的中心显示
size
值。我该怎么做?删除基于角度的 angular 轴标签 并想将我的 自定义标签 作为
A
、B
、C
、D
分别为 45 度、135 度、225 度和 315 度。[已解决] 在极坐标图外的垂直线上显示径向轴标签,而不是它是怎么回事出现在图表内。它应该在垂直规则形式的图表之外,我的自定义标签让我们说
GroupA
、GroupB
、GroupC
、GroupD
.[已解决] 使 鼠标悬停工具提示 放大并在其中显示更多信息。例如,现在,
group
信息显示在工具提示的外面,它应该在行内。正在从工具提示中删除theta
。如何在同心圆上填充灰色并写上文字?对于
ggplot
,我使用图表底部的geom_rect
然后coord_polar
实现了它,但这种方法在polar chart
和plotly
中不起作用。还有其他方法吗?
我知道这对于 plotly
专家来说可能是基本的事情,但自从过去 4 小时以来我一直在努力使事情变得混乱。
我想要类似下面的东西:
到目前为止,我能够解决 SOLVED 项。
R剧情代码:
library(plotly)
df <- data.frame(
r = c(0,1,2,2,1.5,3, 1, 2, 3, 4, 5, 6),
theta = c(0,45,90,315, 180, 270, 10, 40, 70, 100, 130, 160),
group = c('R', 'B', 'G', 'R', 'G', 'B', 'R', 'B', 'G', 'R', 'G', 'B'),
size = c(1, 2, 3, 10, 20, 9, 2, 4, 6, 8, 10, 12)
)
colors_map <- c("blue", "green", "red")
p <- plot_ly(
df,
type = 'scatterpolar',
r = ~r,
theta = ~theta,
color = ~group,
colors = colors_map, #Provide a color mapped vector
size = ~size,
sizes = c(100,200), #Provide a range of size.
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
mode = 'markers',
hoverinfo="text",
marker = list(symbol = 'circle', line = list(width = 2, color = 'lightgrey'))
)%>%
layout(title = 'SAMPLE TITLE',
showlegend = TRUE,
polar = list(
#hole = 0.5,
radialaxis = list(
tickfont = list(
size = 20,
color = "blue"
),
visible = TRUE,
tickcolor = toRGB("red"),
ticks = "outside",
#ticklen = 15,
#tickwidth = 20,
range = c(0, max(df$r)),
rangemode = "tozero",
angle = 90,
tickangle = 90,
tickmode="array",
tickvals = c(0, 1, 2, 3, 4, 5, 6, 7),
ticktext = c('', "One", "Two", "Three", "Four", "Five", "Six", "Seven")
#gridcolor = '#FFF', #color of grid lines
#categoryorder = "array",
#categoryarray = c("GroupA", "GroupB", "GroupC", "GroupD") #Not working
),
angularaxis = list(
tickfont = list(
size = 12
),
rotation = 90,
direction = 'clockwise' ,
categoryarray = c("A", "B", "C", "D") #Not working
)
)
)%>%
add_trace(
r = ~r,
theta = ~theta,
mode = "text",
text = ~size,
textfont = list(color = '#000000', size = 12)
) %>%
add_trace(
r = ~r,
theta = ~theta,
mode = "marker",
opacity = 0.5,
text = ~paste('<b>DETAILS </b><br>---------------<br>Radius:', r, '<br>Theta:', theta, '<br>Group:', group, '<br>Size:', size),
hoverinfo = "text"
)
ggplotly(p)
图表: