EnigmaSong / nethist

R package for Network histogram
https://enigmasong.github.io/nethist/
Other
2 stars 1 forks source link

Using graph figures as x-axis values #14

Open EnigmaSong opened 1 year ago

EnigmaSong commented 1 year ago

This post would be helpful

Here is the code from the post:

library(png)
library(ggtext)
library(tidyverse)
lincoln <- readPNG("test.png") # replace with whatever
labels <- c(virginica = "<img src='test.png' width='100' /><br>*virginica*") # replace with whatever

df <- iris %>% 
  filter(Species == "virginica")

ggplot(df, aes(Species, Sepal.Length)) +
  geom_col() +
  scale_x_discrete(labels = labels) +
  theme(axis.text.x = ggtext::element_markdown())
EnigmaSong commented 1 year ago

Generate figures using the following codes:

library(igraph)

png("inst/violin_summary/v_shape.png")
# par(mfrow=c(2,1),mar=c(0,0,0,0))
v_shape <- graph_from_adjacency_matrix(matrix(c(0,1,0,1,0,1,0,1,0),3,3), mode="undirected")
v_shape$layout <- layout_in_circle
plot(v_shape, vertex.label=NA, vertex.size = 20, edge.width = 20)
dev.off()

png("inst/violin_summary/one_edge.png")
one_edge_three_nodes <- graph_from_adjacency_matrix(matrix(c(0,0,0,0,0,1,0,1,0),3,3), mode="undirected")
one_edge_three_nodes$layout <- layout_in_circle
plot(one_edge_three_nodes, vertex.label=NA, vertex.size = 20, edge.width = 20)
dev.off()

png("inst/violin_summary/triangle.png")#,width = 120, height= 120)
par(mar=c(0,0,0,0))
plot(make_ring(3), vertex.label=NA, vertex.size = 20, edge.width = 20)#triangle
dev.off()

png("inst/violin_summary/square.png")
par(mar=c(0,0,0,0))
plot(make_ring(4), vertex.label=NA, vertex.size = 20, edge.width = 20)#square
dev.off()

png("inst/violin_summary/pentagon.png")
par(mar=c(0,0,0,0))
plot(make_ring(5), vertex.label=NA, vertex.size = 20, edge.width = 20)#pentagon
dev.off()

png("inst/violin_summary/hexagon.png")
par(mar=c(0,0,0,0))
plot(make_ring(6), vertex.label=NA, vertex.size = 20, edge.width = 20)#hexagon
dev.off()

png("inst/violin_summary/septagon.png")
par(mar=c(0,0,0,0))
plot(make_ring(7), vertex.label=NA, vertex.size = 20, edge.width = 20)#septagon
dev.off()
EnigmaSong commented 1 year ago

The earlier version causes issue on R CMD CHECK.

This is due to the path of image files. I put the image files under inst/violin_summary folder as above, but when R CMD CHECK runs, file is under nethist/viloin_summary while the test code is in tests/test_that.