Hi R and plotly experts,
I am trying my hands on plotly
lately.
Here is my simple minimal design code:
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)
The chart ploted is:
I have tried something based on documentaion but couldn't achieve. Here are the items I failed to render[Few of them are solved and posted in answer]:
[SOLVED] Show color of points based on which group it belongs. If it belongs to
R
group, then color should be red, ifB
then blue and ifG
then green.[SOLVED] Size of points shown in polar chart is quite small, is there a way I can enlarge it or give a range of size ?
[SOLVED] In middle of each point, I want to show a text/number, let's say I want to show
size
value on the center of each point. How I can do this ?remove the angle based angular axis labels and want to put my custom label as
A
,B
,C
,D
at 45deg, 135deg, 225deg and 315deg respectively.[SOLVED] show radial axis label in vertical line outside polar chart, instead, of how it is present inside the chart. It should be outside the chart in vertical rule form, with my custom labels let's say
GroupA
,GroupB
,GroupC
,GroupD
.[SOLVED] Make mouseover tooltip to be enlarged and show more information inside it. For example, Right now, the
group
information is shown outside the tooltip, it should be inside the row. Removingtheta
from tooltip.How to have concentric circle with grey color filled and a text written on it.? With
ggplot
I implemented it using ageom_rect
at the bottom of chart and thencoord_polar
, but that approach will not work inpolar chart
withplotly
. Any other approach ?
I understand this could be basic things for plotly
experts, but I am struggling and complicating things out of order since last 4 hours.
I want something similar as below: I am sure, this question will go long way in helping beginners in customizing plotly polar chart visuals as no online help is available and SO question addressing it. Any help is appreciated.