R highcharter - trim row labels but not in tooltip - r-highcharter

I want to display a highcharter stacked bar chart where the row labels are trimmed that the first five characters are not shown. However, in the tooltip the full category names should be shown.
In the example above as categories at the xAxis I would like to have only "2012", "2013",.., whereas in the tooltip the whole category names should be displayed.
Here is my code
bs.table = data.frame(
Closing.Date = c("Line 2012", "Year 2013", "Year 2014", "Year 2015", "Year 2016"),
Non.Current.Assets = c(40.4, 30.3, 20.4, 34.5, 20),
Current.Assets = c(3.2, 3.3, 2.4, 3.5, 2)
)
hc <- highchart() %>%
hc_chart(type = "bar") %>%
hc_plotOptions(series = list(stacking = "normal")) %>%
hc_xAxis(categories = bs.table$Closing.Date,
lineColor = 'transparent',
tickWidth = 0,
labels = list(enable = TRUE,
align = 'left',
x = 5,
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_add_series(name ="Non Current Assets",
data = bs.table$Current.Assets,
stack = "Assets",
dataLabels = list(enabled = TRUE,
inside = TRUE,
align = "right",
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_add_series(name = "Current Assets",
data = bs.table$Non.Current.Assets,
stack = "Assets",
dataLabels = list(enabled = TRUE, inside = FALSE, align = "right",
style = list(fontSize = '1em',color = '#fff')) ) %>%
hc_legend(enabled = FALSE) %>%
hc_tooltip(shared = TRUE,
headerFormat = '<b>Statement {point.x}</b><br>',
pointFormat = '<b>{series.name}:</b> {point.y} <br>',
footerFormat = '<b>Total: {point.total} </b>')
Many thanks in advance!

Could you not just change the column name before you create the chart?
# function to get year
substrRight <- function(x, n){
substr(x, nchar(x)-n+1, nchar(x))
}
# create year column
bs.table$year = substrRight(as.character(bs.table$Closing.Date), 4)
# alter x axis to use this column
hc <- highchart() %>%
hc_chart(type = "bar") %>%
hc_plotOptions(series = list(stacking = "normal")) %>%
hc_xAxis(categories = bs.table$year,
lineColor = 'transparent',
tickWidth = 0,
labels = list(enable = TRUE,
align = 'left',
x = 5,
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_add_series(name ="Non Current Assets",
data = bs.table$Current.Assets,
stack = "Assets",
dataLabels = list(enabled = TRUE,
inside = TRUE,
align = "right",
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_add_series(name = "Current Assets",
data = bs.table$Non.Current.Assets,
stack = "Assets",
dataLabels = list(enabled = TRUE, inside = FALSE, align = "right",
style = list(fontSize = '1em',color = '#fff')) ) %>%
hc_legend(enabled = FALSE) %>%
hc_tooltip(shared = TRUE,
headerFormat = '<b>Statement {point.x}</b><br>',
pointFormat = '<b>{series.name}:</b> {point.y} <br>',
footerFormat = '<b>Total: {point.total} </b>')
Edit
This is a sort of workaround that would nearly give you what you want:
highchart() %>%
hc_chart(type = "bar") %>%
hc_xAxis(categories = bs.table$year,
lineColor = 'transparent',
tickWidth = 0,
labels = list(enable = TRUE,
align = 'left',
x = 5,
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_plotOptions(series = list(stacking = "normal")) %>%
hc_add_series(name = "Current Assets", bs.table, "column", hcaes(x = year, y = Current.Assets, stuff = Closing.Date),
tooltip = list(pointFormat = "<b>{point.stuff}</b><br> <b>{series.name}:</b> {point.y} <br>"),
dataLabels = list(enabled = TRUE,
inside = TRUE,
align = "right",
style = list(fontSize = '1em',color = '#fff'))) %>%
hc_add_series(name ="Non Current Assets", bs.table, "column", hcaes(x = year, y = Non.Current.Assets),
tooltip = list(pointFormat = "<b>{point.stuff}</b><br>"),
dataLabels = list(enabled = TRUE, inside = FALSE, align = "right",
style = list(fontSize = '1em',color = '#fff')) ) %>%
hc_legend(enabled = FALSE) %>%
hc_tooltip(shared = TRUE,
headerFormat = '<b>Statement </b>',
footerFormat = '<b>Total: {point.total} </b>')

Related

How to change color of mark on topoplot interactively?

I want to create interactive line- and topoplot depending on menu. I figured out how to make red the line chosen in menu, but it doesn't work for topoplot marks (black circles inside topoplot). I can change it manually (cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)), but how to do that interactively?
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1:3, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
N = 1:length(pos) #1:4
hidespines!(ax, :t, :r)
GLMakie.xlims!(-0.3, 1.2)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
times = range(-0.3, length=size(dat_e,2), step=1 ./ 128)
lines = Dict()
for i in N
mean_trial = mean(dat_e[i,:,:],dims=2)[:,1]
line = lines!(times, mean_trial, color = "black")
lines[i] = line
end
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
topo_axis = Axis(f[2, 2], width = 178, height = 178, aspect = DataAspect())
Makie.xlims!(low = -0.2, high = 1.2)
Makie.ylims!(low = -0.2, high = 1.2)
topoMatrix = eegHeadMatrix(pos[N], (0.5, 0.5), 0.5)
cmap = Observable(collect(ColorScheme(range(colorant"black", colorant"black", length=30))))
#cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)
topo = eeg_topoplot!(topo_axis, N, # averaging all trial of 30 participants on Xth msec
raw.ch_names[1:30];
positions=pos, # produced automatically from ch_names
interpolation=NullInterpolator(),
enlarge=1,
#colorrange = (0, 1), # add the 0 for the white-first color
colormap = cmap[],
label_text=false)
hidedecorations!(current_axis())
hidespines!(current_axis())
num_prev = 0
menu = Menu(f[3, 2], options = raw.ch_names[1:30], default = nothing)#, default = "second")
on(menu.selection) do selected
if selected != nothing
num = findall(x->x==menu.selection[], raw.ch_names[1:30])[]
if num_prev != 0
lines[num_prev].color = "black"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
end
lines[num].color = "red"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
num_prev = num
end
end
notify(menu.selection)
#print(cmap[])
f
We solved this by putting this string at the end of the menu.selection section:
notify(lines)
It works, because lines() automatically creates Observable.

R plotly line color by value range

I would like to make this kind of graph (here from Our World In data ) where the line color varies by value range.
edit : adding a screenshot to make it clearer :
With plotly, I found this example but working with type = scatter and mode = markers plot and not with lines:
x <- seq(from = -2,
to = 2,
b = 0.1)
y <- sin(x)
p11 <- plot_ly() %>%
add_trace(type = "scatter",
x = ~x,
y = ~y,
mode = "markers",
marker = list(size = 10,
color = colorRampPalette(brewer.pal(10,"Spectral"))(41))) %>%
layout(title = "Multicolored sine curve",
xaxis = list(title = "x-axis"),
yaxis = list(title = "y-axis"))
p11
is there any ways to use the colorRampPalette or values range but with line (actually it's a time series)
x <- seq(from = -2,
to = 2,
b = 0.1)
y <- sin(x)
p11 <- plot_ly() %>%
add_trace(type = "scatter",
x = ~x,
y = ~y,
mode = "lines",
line = list(width = 1,
color = colorRampPalette(brewer.pal(10,"Spectral"))(41))) %>%
layout(title = "Multicolored sine curve",
xaxis = list(title = "x-axis"),
yaxis = list(title = "y-axis"))
p11
Thank you
You can, but the more points you have the better it will look. Note that I change the .1 in x, to .001.
library(plotly)
library(RColorBrewer)
x <- seq(from = -2,
to = 2,
b = 0.001)
y <- sin(x)
z = cut(x, breaks = 5, include.lowest = T)
p11 <- plot_ly() %>%
add_lines(x = ~x,
y = ~y,
color = ~z,
colors = colorRampPalette(brewer.pal(10,"Spectral"))(length(x))) %>%
layout(title = "Multicolored sine curve",
xaxis = list(title = "x-axis"),
yaxis = list(title = "y-axis"))
p11
If I change that .001 back to .1, it's a bit ugly! You can see the gaps.

How to get real Landsat image conrers

How I can get actual coordinates of Landsat image corners (see image to understand) ?
From metadata file (..._MTL.txt) I can get coordinates of red corners, but I need to get coordinates of green corners.
I work with GeoTIFF files using GDAL.
I need to get correct latitude and longitude of green points.
Can I do it using python3?
Thanks for help
Metadata file
GROUP = L1_METADATA_FILE
GROUP = METADATA_FILE_INFO
ORIGIN = "Image courtesy of the U.S. Geological Survey"
REQUEST_ID = "9991103150002_00325"
PRODUCT_CREATION_TIME = 2011-03-16T20:14:24Z
STATION_ID = "EDC"
LANDSAT5_XBAND = "1"
GROUND_STATION = "IKR"
LPS_PROCESSOR_NUMBER = 0
DATEHOUR_CONTACT_PERIOD = "1016604"
SUBINTERVAL_NUMBER = "01"
END_GROUP = METADATA_FILE_INFO
GROUP = PRODUCT_METADATA
PRODUCT_TYPE = "L1T"
ELEVATION_SOURCE = "GLS2000"
PROCESSING_SOFTWARE = "LPGS_11.3.0"
EPHEMERIS_TYPE = "DEFINITIVE"
SPACECRAFT_ID = "Landsat5"
SENSOR_ID = "TM"
SENSOR_MODE = "BUMPER"
ACQUISITION_DATE = 2010-06-15
SCENE_CENTER_SCAN_TIME = 04:57:44.2830500Z
WRS_PATH = 145
STARTING_ROW = 26
ENDING_ROW = 26
BAND_COMBINATION = "1234567"
PRODUCT_UL_CORNER_LAT = 49.8314223
PRODUCT_UL_CORNER_LON = 84.0018859
PRODUCT_UR_CORNER_LAT = 49.8694055
PRODUCT_UR_CORNER_LON = 87.4313889
PRODUCT_LL_CORNER_LAT = 47.8261840
PRODUCT_LL_CORNER_LON = 84.1192898
PRODUCT_LR_CORNER_LAT = 47.8615913
PRODUCT_LR_CORNER_LON = 87.4144676
PRODUCT_UL_CORNER_MAPX = 284400.000
PRODUCT_UL_CORNER_MAPY = 5524200.000
PRODUCT_UR_CORNER_MAPX = 531000.000
PRODUCT_UR_CORNER_MAPY = 5524200.000
PRODUCT_LL_CORNER_MAPX = 284400.000
PRODUCT_LL_CORNER_MAPY = 5301000.000
PRODUCT_LR_CORNER_MAPX = 531000.000
PRODUCT_LR_CORNER_MAPY = 5301000.000
PRODUCT_SAMPLES_REF = 8221
PRODUCT_LINES_REF = 7441
PRODUCT_SAMPLES_THM = 4111
PRODUCT_LINES_THM = 3721
BAND1_FILE_NAME = "L5145026_02620100615_B10.TIF"
BAND2_FILE_NAME = "L5145026_02620100615_B20.TIF"
BAND3_FILE_NAME = "L5145026_02620100615_B30.TIF"
BAND4_FILE_NAME = "L5145026_02620100615_B40.TIF"
BAND5_FILE_NAME = "L5145026_02620100615_B50.TIF"
BAND6_FILE_NAME = "L5145026_02620100615_B60.TIF"
BAND7_FILE_NAME = "L5145026_02620100615_B70.TIF"
GCP_FILE_NAME = "L5145026_02620100615_GCP.txt"
METADATA_L1_FILE_NAME = "L5145026_02620100615_MTL.txt"
CPF_FILE_NAME = "L5CPF20100401_20100630_09"
END_GROUP = PRODUCT_METADATA
GROUP = MIN_MAX_RADIANCE
LMAX_BAND1 = 193.000
LMIN_BAND1 = -1.520
LMAX_BAND2 = 365.000
LMIN_BAND2 = -2.840
LMAX_BAND3 = 264.000
LMIN_BAND3 = -1.170
LMAX_BAND4 = 221.000
LMIN_BAND4 = -1.510
LMAX_BAND5 = 30.200
LMIN_BAND5 = -0.370
LMAX_BAND6 = 15.303
LMIN_BAND6 = 1.238
LMAX_BAND7 = 16.500
LMIN_BAND7 = -0.150
END_GROUP = MIN_MAX_RADIANCE
GROUP = MIN_MAX_PIXEL_VALUE
QCALMAX_BAND1 = 255.0
QCALMIN_BAND1 = 1.0
QCALMAX_BAND2 = 255.0
QCALMIN_BAND2 = 1.0
QCALMAX_BAND3 = 255.0
QCALMIN_BAND3 = 1.0
QCALMAX_BAND4 = 255.0
QCALMIN_BAND4 = 1.0
QCALMAX_BAND5 = 255.0
QCALMIN_BAND5 = 1.0
QCALMAX_BAND6 = 255.0
QCALMIN_BAND6 = 1.0
QCALMAX_BAND7 = 255.0
QCALMIN_BAND7 = 1.0
END_GROUP = MIN_MAX_PIXEL_VALUE
GROUP = PRODUCT_PARAMETERS
CORRECTION_METHOD_GAIN_BAND1 = "CPF"
CORRECTION_METHOD_GAIN_BAND2 = "CPF"
CORRECTION_METHOD_GAIN_BAND3 = "CPF"
CORRECTION_METHOD_GAIN_BAND4 = "CPF"
CORRECTION_METHOD_GAIN_BAND5 = "CPF"
CORRECTION_METHOD_GAIN_BAND6 = "IC"
CORRECTION_METHOD_GAIN_BAND7 = "CPF"
CORRECTION_METHOD_BIAS = "IC"
SUN_AZIMUTH = 141.2669762
SUN_ELEVATION = 59.9909680
OUTPUT_FORMAT = "GEOTIFF"
END_GROUP = PRODUCT_PARAMETERS
GROUP = CORRECTIONS_APPLIED
STRIPING_BAND1 = "NONE"
STRIPING_BAND2 = "NONE"
STRIPING_BAND3 = "NONE"
STRIPING_BAND4 = "NONE"
STRIPING_BAND5 = "NONE"
STRIPING_BAND6 = "NONE"
STRIPING_BAND7 = "NONE"
BANDING = "N"
COHERENT_NOISE = "N"
MEMORY_EFFECT = "Y"
SCAN_CORRELATED_SHIFT = "Y"
INOPERABLE_DETECTORS = "N"
DROPPED_LINES = "N"
END_GROUP = CORRECTIONS_APPLIED
GROUP = PROJECTION_PARAMETERS
REFERENCE_DATUM = "WGS84"
REFERENCE_ELLIPSOID = "WGS84"
GRID_CELL_SIZE_THM = 60.000
GRID_CELL_SIZE_REF = 30.000
ORIENTATION = "NUP"
RESAMPLING_OPTION = "CC"
MAP_PROJECTION = "UTM"
END_GROUP = PROJECTION_PARAMETERS
GROUP = UTM_PARAMETERS
ZONE_NUMBER = 45
END_GROUP = UTM_PARAMETERS
END_GROUP = L1_METADATA_FILE
END
You might first find the contour with the biggest area. Then try some algorithm to find the points you want. It seems that the satellite picture in the image is not a perfect rectangle, so you can't fit a rectangle on it using OpenCV's built-in methods.
You should try something like that:
import cv2
import numpy as np
img = cv2.imread('z_edited.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(imgray, (11, 11), 0)
ret, thresh = cv2.threshold(blurred, 27, 255, 0)
cnts, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
max_area = 0
max_area_index = 0
for i, cnt in enumerate(cnts):
area = cv2.contourArea(cnt)
if area > max_area:
max_area = area
max_area_index = i
x_min = np.min(cnts[max_area_index][:, 0, 0])
x_max = np.max(cnts[max_area_index][:, 0, 0])
y_min = np.min(cnts[max_area_index][:, 0, 1])
y_max = np.max(cnts[max_area_index][:, 0, 1])
(x_left, y_left) = (x_min, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_min)), 0, 1])
(x_right, y_right) = (x_max, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_max)), 0, 1])
(x_down, y_down) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_max)), 0, 0], y_max)
(x_top, y_top) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_min)), 0, 0], y_min)
cv2.circle(img, (x_left, y_left), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_right, y_right), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_down, y_down), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_top, y_top), 10, (0, 0, 255), thickness=8)
# cv2.drawContours(img, cnts, max_area_index, (0, 255, 0), 2)
cv2.namedWindow('s', cv2.WINDOW_NORMAL)
cv2.imshow('s', img)
cv2.waitKey(0)
And the result looks like:
Using this code you can find the coordinates of the corners of the satellite picture inside the image(red points).
Also need to say I have assumed that your satellite picture background is completely black(the image you have uploaded, has a thin gray strip around the whole image).

Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: could not convert string to float: Null

I am doing deep learning using Keras in Rstudio. I have some embedding layers at the beginning of the model. I checked continuous variables and there is no missing value, and also responding variable y is float.
df_cl_dl = df_cl %>% filter(agency == "FHA") %>%
select(lender, channel, fthb, region, credit_score, credit_score_null, source, ltv_uw, seasonality,
current_ltv, loan_age, cash_incentive_a, hpas, loan_size, ur, risk,
vsmm) %>%
sample_n(100000)
inp_lender = layer_input(shape = c(1), name = "inp_lender")
inp_channel = layer_input(shape = c(1), name = "inp_channel")
inp_fthb = layer_input(shape = c(1), name = "inp_fthb")
inp_region = layer_input(shape = c(1), name = "inp_region")
inp_cs_null = layer_input(shape = c(1), name = "inp_cs_null")
inp_source = layer_input(shape = c(1), name = "inp_source")
inp_season = layer_input(shape = c(1), name = "inp_season")
inp_ltv_uw = layer_input(shape = c(1), name = "inp_ltv_uw")
inp_continuous = layer_input(shape = c(8), name = "inp_continuous")
embedding_out1 = inp_lender %>% layer_embedding(input_dim = 3+1, output_dim = 2, input_length = 1, name = "embedding_lender") %>% layer_flatten()
embedding_out2 = inp_channel %>% layer_embedding(input_dim = 3+1, output_dim = 2, input_length = 1, name = "embedding_channel") %>% layer_flatten()
embedding_out3 = inp_fthb %>% layer_embedding(input_dim = 3+1, output_dim = 2, input_length = 1, name = "embedding_fthb") %>% layer_flatten()
embedding_out4 = inp_region %>% layer_embedding(input_dim = 4+1, output_dim = 2, input_length = 1, name = "embedding_region") %>% layer_flatten()
embedding_out5 = inp_cs_null %>% layer_embedding(input_dim = 2+1, output_dim = 2, input_length = 1, name = "embedding_cs_null") %>% layer_flatten()
embedding_out6 = inp_source %>% layer_embedding(input_dim = 2+1, output_dim = 2, input_length = 1, name = "embedding_source") %>% layer_flatten()
embedding_out7 = inp_season %>% layer_embedding(input_dim = 12+1, output_dim = 3, input_length = 1, name = "embedding_season") %>% layer_flatten()
embedding_out8 = inp_ltv_uw %>% layer_embedding(input_dim = 2+1, output_dim = 2, input_length = 1, name = "embedding_ltv_uw") %>% layer_flatten()
combined_model = layer_concatenate(c(embedding_out1, embedding_out2, embedding_out3, embedding_out4,
embedding_out5, embedding_out6, embedding_out7, embedding_out8, inp_continuous)) %>%
layer_dense(units=32, activation = "relu") %>%
layer_dropout(0.3) %>%
layer_dense(units=10, activation = "relu") %>%
layer_dropout(0.15) %>%
layer_dense(units=1)
model = keras::keras_model(inputs = c(inp_lender, inp_channel, inp_fthb, inp_region, inp_cs_null,
inp_source, inp_season, inp_ltv_uw, inp_continuous),
outputs = combined_model)
model %>% compile(loss = "mean_squared_error", optimizer = "sgd", metric = "accuracy")
inputVariables = list(as.matrix(df_cl_dl$lender),
as.matrix(df_cl_dl$channel),
as.matrix(df_cl_dl$fthb),
as.matrix(df_cl_dl$region),
as.matrix(df_cl_dl$credit_score_null),
as.matrix(df_cl_dl$source),
as.matrix(df_cl_dl$seasonality),
as.matrix(df_cl_dl$ltv_uw),
as.matrix(df_cl_dl[,c("credit_score", "current_ltv", "loan_age", "cash_incentive_a", "hpas", "loan_size", "ur", "risk")]))
model %>% fit(x = inputVariables, y = as.matrix(df_cl_dl$vsmm), epochs = 10, batch_size = 2)
Error Massage:
Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: could not convert string to float: Null

Is there functionality in plotly to do something similar to hjust/vjust or position_dodge in R?

I'm hoping to adjust the location of points and lines in a dumbbell plot to separate the bars rather than overlaying them, similar to position dodge or hjust/vjust in R.
The code below produces something close to what I'd like, but the barbells are overlayed.
urlfile <- 'https://raw.githubusercontent.com/charlottemcclintock/GenSquared/master/data.csv'
df <- read.csv(urlfile)
p <- plot_ly(df, color = I("gray80")) %>%
add_segments(x = ~mom, xend = ~daughter, y = ~country, yend = ~country, showlegend = FALSE) %>%
add_markers(x = ~mom, y = ~country, name = "Mother", color = I("purple")) %>%
add_markers(x = ~daughter, y = ~country, name = "Daughter", color = I("pink")) %>%
add_segments(x = ~dad, xend = ~son, y = ~country, yend = ~country, showlegend = FALSE) %>%
add_markers(x = ~dad, y = ~country, name = "Father", color = I("navy")) %>%
add_markers(x = ~son, y = ~country, name = "Son", color = I("blue")) %>%
layout(
title = "Gender educational disparity",
xaxis = list(title = "Mean Years of Education"),
margin = list(l = 65)
)
p
By coercing the country names to a factor, I can get the ideal spacing but I lose the country labels which I'm hoping to keep. I tried using country and numeric factor index together but plotly doesn't allow discrete and continuous scales together.
df$cnum <- as.numeric(as.factor(df$country))
p <- plot_ly(df, color = I("gray80")) %>%
add_segments(x = ~mom, xend = ~daughter, y = ~cnum+.2, yend = ~cnum+0.2, showlegend = FALSE) %>%
add_markers(x = ~mom, y = ~cnum+.2, name = "Mother", color = I("purple")) %>%
add_markers(x = ~daughter, y = ~cnum+.2, name = "Daughter", color = I("pink")) %>%
add_segments(x = ~dad, xend = ~son, y = ~cnum-.2, yend = ~cnum-.2, showlegend = FALSE) %>%
add_markers(x = ~dad, y = ~cnum-.2, name = "Father", color = I("navy")) %>%
add_markers(x = ~son, y = ~cnum-.2, name = "Son", color = I("blue")) %>%
layout(
title = "Gender educational disparity",
xaxis = list(title = "Mean Years of Education"),
margin = list(l = 65)
)
p
I would like it to look like this:
But with the country names on the y-axis.
Is there a way to adjust the vertical height relative to a discrete axis point?
Update: it's not elegant but I figured out a workaround by overwriting the y axis with a section y axis! Would still love a better answer, but this is a usable fix!
df$arb=15
plot_ly(df, color = I("gray80")) %>%
add_segments(x = ~mom, xend = ~daughter, y = ~cnum+.2, yend = ~cnum+.2, showlegend = FALSE) %>%
add_markers(x = ~mom, y = ~cnum+.2, name = "Mother", color = I("purple"), size=2) %>%
add_markers(x = ~daughter, y = ~cnum+.2, name = "Daughter", color = I("pink"), size=2) %>%
add_segments(x = ~dad, xend = ~son, y = ~cnum-.1, yend = ~cnum-.1, showlegend = FALSE) %>%
add_markers(x = ~dad, y = ~cnum-.1, name = "Father", color = I("navy"), size=2) %>%
add_markers(x = ~son, y = ~cnum-.1, name = "Son", color = I("blue"), size=2) %>%
add_markers(x = ~arb, y = ~country, name = " ", color = I("white"), yaxis = "y2") %>%
layout(
yaxis=list(title="", tickfont=list(color="white")),
yaxis2 = list(overlaying = "y", side = "left", title = ""))
)

Resources