sorry for my english,
I'm trying to customize a "scatter" chart with "HighCharts" in R to use with rMarkDown and generate html and pdf output. So far I have been able to partially configure.
1. Treat the extreme values, at this moment an extreme value prevents the adequate visualization of the graph, it could be excluded with R, but it would be better if it was hidden in the graph, being able to incorporate it through the legend where all the municipalities are shown.
2. Show one of the municipalities in a different color.
3. The dataLabels show one of the "Umbral" variables, but it should be the "Municipio" variable.
4. The tooltip currently shows the values for each municipality, but they should be displayed as a table incorporating the names of the variables, "Esfuerzo" "Umbral" "Relevancia" "Municipio"
5. The legend with the municipalities should be initially hidden and with a button to be able to show or hide it.
6. Incorporate the median value into the text of the plotLine lines To be able to add one or more texts whose position is referenced at the same time to the axes (x, y).
Code: Select all
hc <- dfo %>%
hchart(
type = "scatter",
hcaes(
x = dfo$`Esfuerzo`,
y = dfo$`Umbral`,
size = dfo$`Relevancia` * 100,
group = dfo$`Municipio`
),
tooltip = list(
valueDecimals = 2,
valueSuffix = " %"
),
dataLabels = list(
enabled=TRUE,
format='{y:.2f}',
style = list(fontSize = "16px"),
color = "#666666"
)
) %>%
hc_title(
text = "Compromiso",
style = list(fontWeight = "bold", fontSize = "28px")
) %>%
hc_subtitle(
text = "",
align = "center",
style = list(fontWeight = "bold", fontSize = "18px")
) %>%
hc_xAxis(
labels = list(style = list(fontSize = "14px")),
title = list(
text = "Esfuerzo",
style = list(fontWeight = "bold", fontSize = "20px")
),
plotLines = list(
list(label = list(text = ""),
color = "#FF4040",
width = 3,
value = median(dfo$`Esfuerzo`)
)
)
) %>%
hc_yAxis(
labels = list(style = list(fontSize = "14px")),
title = list(
text = "% Umbral",
style = list(fontWeight = "bold", fontSize = "20px")
),
plotLines = list(
list(label = list(text = ""),
color = "#FF4040",
width = 3,
value = median(dfo$`Umbral`)
)
)
) %>%
hc_exporting (
enabled = TRUE
) %>%
hc_add_theme(
hc_theme_tufte()
)
hc
Code: Select all
structure(list(Código = c("02003", "03014", "04013", "05019",
"06015", "07040", "08019", "09059", "10037", "11012", "12040",
"13034", "14021", "15030", "16078", "17079", "18087", "19130",
"21041", "22125", "23050", "24089", "25120", "26089", "27028",
"28079", "29067", "30030", "32054", "33044", "34120", "35016",
"36038", "37274", "38038", "39075", "40194", "41091", "42173",
"43148", "44216", "45168", "46250", "47186", "49275", "50297",
"51001", "52001"), Municipio = c("Albacete", "Alicante/Alacant",
"Almería", "Ávila", "Badajoz", "Palma", "Barcelona", "Burgos",
"Cáceres", "Cádiz", "Castellón de la Plana/Castelló de la Plana",
"Ciudad Real", "Córdoba", "Coruña (A)", "Cuenca", "Girona", "Granada",
"Guadalajara", "Huelva", "Huesca", "Jaén", "León", "Lleida",
"Logroño", "Lugo", "Madrid", "Málaga", "Murcia", "Ourense", "Oviedo",
"Palencia", "Palmas de Gran Canaria (Las)", "Pontevedra", "Salamanca",
"Santa Cruz de Tenerife", "Santander", "Segovia", "Sevilla",
"Soria", "Tarragona", "Teruel", "Toledo", "Valencia", "Valladolid",
"Zamora", "Zaragoza", "Ceuta", "Melilla"), Esfuerzo = c(66.255518296917,
55.4505971732305, 67.3396882117212, 159.444527678894, 39.9208624778303,
75.6407281816124, 191.885593614053, 66.4060669160645, 41.5696869168135,
131.928027073733, 70.8156033699513, 63.3576317305502, 99.9022751874716,
92.1737310681322, 38.5831640425687, 91.7932459374022, 108.74338544486,
42.8257587497772, 67.209950935465, 52.5816548264175, 102.778140636216,
81.7958449372392, 87.2101693767431, 82.8515582299525, 64.2431323026685,
116.244125268106, 95.4495291756444, 57.9232964761993, 74.9121459540308,
75.0079722742974, 72.345751914009, 131.407698477426, 37.4719669533452,
70.9266085324988, 119.707963542996, 56.4080210059843, 76.5130914290131,
102.864800169414, 155.927878655384, 96.0587342879086, 57.0368704204712,
43.3062216835242, 83.7300653585645, 68.8468635870744, 57.9772431037523,
112.835558277614, 189.188525288669, 431.185251161171), Relevancia = c(0.0779438999416286,
0.075567624299619, 0.0830963177638657, 0.181216919752304, 0.0645578573307309,
0.0694739535415282, 0.11238222267336, 0.0591312044270579, 0.0549171188507039,
0.107335017649502, 0.0672279971174195, 0.0622048291208239, 0.106492447121433,
0.0989219226252717, 0.0434299324062133, 0.080124826578867, 0.0923126527122762,
0.055862728725791, 0.0816954005957221, 0.0569671724881646, 0.0902113572693082,
0.0760249770659709, 0.0786282259767798, 0.0920644595378507, 0.0827523660072055,
0.0869155856787086, 0.0892429670963684, 0.0705333155849015, 0.0852996555846074,
0.069397881679441, 0.0843127745258698, 0.151586054295292, 0.0464492613233081,
0.0720415327066066, 0.119890097237675, 0.0503879549782981, 0.0624360563921389,
0.0965284452003263, 0.159516287787606, 0.0739061270776166, 0.0694730992371514,
0.0410407530273502, 0.0855901086450992, 0.0787793734678359, 0.0688139147586614,
0.102143947795215, 0.0634263210053491, 0.149047512460091), Umbral = c(21,
28.8, 30.3, 19.2, 24.4, 16.8, 15.4, 12.8, 19.4, 20.3, 20.7, 18.6,
24.6, 16.5, 19.4, 18.2, 24.8, 16.8, 26.5, 16.2, 20.5, 16.9, 21.4,
16.5, 19.3, 17.3, 27.9, 24, 19.8, 16.7, 15.1, 25.6, 19.9, 20.5,
27, 17.8, 18.2, 24.9, 13.6, 19.3, 13.1, 14.5, 21.6, 15.1, 20.4,
14.9, 34.8, 37)), class = "data.frame", row.names = c(NA, -48L
))