Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge labeled with Greek letter and subscripted number? #44

Open
Jinsong-Chen opened this issue Jan 20, 2022 · 4 comments
Open

Edge labeled with Greek letter and subscripted number? #44

Jinsong-Chen opened this issue Jan 20, 2022 · 4 comments

Comments

@Jinsong-Chen
Copy link

Hi,

Nice package!
Can the edges be labeled with Greek letters and/or subscripted numbers (e.g., \lambda_{11} for factor one to item one)?

Best
Jinsong

@cjvanlissa
Copy link
Owner

I'm not sure. The plot is a ggplot, so it can do anything ggplot can do. I am not very familiar with plotting Greek letters, so please let me know if you knowmore. To help you on the way: the edge labels are taken from a column of a data.frame, with class "character". If it is somehow possible to parse these character strings, then it might be possible. Alternatively, you could just add the labels you want to the plot by hand, e.g.:

p <- graph_sem(model)
p + whatever the geom is to get Greek letters

@Jinsong-Chen
Copy link
Author

Thanks for reminding. It seems Greek letter can be labeled using unicode. Meanwhile, I have two more questions:

  1. The diagram doesn't look good if it's drew horizontally (e.g., factors on left + items on right). Can it be improved?
  2. Can the shape of nodes be triangle (e.g., for intercept) or NA (e.g., no shape or border line)?

@cjvanlissa
Copy link
Owner

Point 1. can be addressed just by altering the layout and using coord_fixed. Point 2: You can make the line color of a node white, which would achieve your goal; triangles are not implemented yet; the main issue would be that the code for where to connect edges would have to be completely refactored. Currently, they are connected at 4 extremes of a node. A triangle has only 3 extremes, and they are in different positions. I will consider it, but it's not a priority atm.

@Jinsong-Chen
Copy link
Author

Jinsong-Chen commented Jan 20, 2022

I'm not sure. The plot is a ggplot, so it can do anything ggplot can do. I am not very familiar with plotting Greek letters, so please let me know if you knowmore. To help you on the way: the edge labels are taken from a column of a data.frame, with class "character". If it is somehow possible to parse these character strings, then it might be possible. Alternatively, you could just add the labels you want to the plot by hand, e.g.:

p <- graph_sem(model)
p + whatever the geom is to get Greek letters

Seems it might work with something like:
p <- graph_sem(edges,layout,nodes)
p+geom_text(aes(x,y,label=expression(lambda_{11})),parse = TRUE)

But then one needs to obtain the x and y coordinates of the edges. I am using the edges, nodes and layout arguments in graph_sem() for drawing (i.e., no model or data). Do you know how I can obtain the coordinates?

Edit: Actually, it might be better to have additional "label" arguments for the edges and nodes in graph_sem so that one can vectorize the label (i.e., not as data.frame) and parse it or use expression for any math or special symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants