Closed discoleo closed 2 years ago
Note:
layoutSplit = function(x, y=NULL, nr=2, scale=c(1, 30), dx=3) {
len = nchar(x);
if( ! is.null(y)) len = pmax(len, nchar(y));
len = len + dx;
if(nr > 1) {
nm = length(len) %% nr;
if(nm != 0) len = c(len, rep(0, nr - nm));
} else nm = 0;
nc = length(len) %/% nr;
len = matrix(len, ncol=nr);
# x-Coord = cumsum() + mid;
pos = apply(len, 2, cumsum);
pos = rbind(0, pos[ - nrow(pos), ]);
pos = pos + len / 2; # midpoint
dim(pos) = NULL;
pos = pos * scale[1];
xdf = data.frame(
x = pos,
y = rep(seq(nr, 1, by=-1) * scale[2], each=nc));
if(nm > 0) {
xdf = xdf[ seq(nr - nm) - 1 - nrow(xdf), ];
}
return(xdf)
}
improved labeling requires that the nudge_y argument is also visible;
idS = 1
txtS = ann[ann$sentence_id == idS, ];
textplot_dependencyparser(txtS, layout = layoutSplit(txtS$token, txtS$upos, nr=2), nudge_y = -5)
proof of concept hack (based on internal code);
[...]
ggraph::ggraph(g, layout = layoutSplit(x$token, y = x$upos, nr=2)) +
[...]
We can certainly add the layout argument in the function definition so that you can pass whichever on.
Note getting this currently with your layoutSplit
Latest version of layoutSplit:
Note:
I've added the layout argument in commit https://github.com/bnosac/textplot/commit/6097d2b0453ad19d01b03e55dd17e88bccbbec8d and will upload the package to CRAN
Function textplot_dependencyparser.default
Add a layout argument:
Code changes
Example
Problem:
Sentence
idS = 1 textplot_dependencyparser(ann[ann$sentence_id == idS,])