| Title: | Visualise the Anatomical Therapeutic Chemical (ATC) Hierarchy |
|---|---|
| Description: | Visualisation and subsetting of the World Health Organisation Anatomical Therapeutic Chemical (ATC) classification system. |
| Authors: | J Matthews [aut, cre, cph] |
| Maintainer: | J Matthews <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0.9000 |
| Built: | 2026-10-14 14:25:51 UTC |
| Source: | https://github.com/jnm212/visatc |
find a subset of the tree
## S4 method for signature 'atctree' x[i, j = 1L]## S4 method for signature 'atctree' x[i, j = 1L]
x |
object of class atctree |
i |
label (ATC code) of focal node |
j |
generation (integer). 0: siblings, -1: children, -2: grandchildren, 1: parents etc |
The subset method for objects of class atctree uses a focal node and a specification of how many generations to accrue. The focal node is specified by an ATC code at any of the five levels (e.g. i="A01"). The generation is specified by integer j, signed positive for ancestors and negative for descendants.
an object of class atctree
h <- atctree(schema="full") #more useful to use the full tree with this approach # plot descendents of P01 (as far as grandchildren): h["P01",-2] |> plot(stem_label=TRUE, leaf_label=TRUE) # plot descendents of P01 (as far as great grandchildren): h["P01",-3] |> plot(stem_label=TRUE, leaf_label=FALSE) # plot descendents of parent of P01A: h["P01A",1] |> plot(stem_label=TRUE, leaf_label=TRUE) # plot descendents of grandparent of P01A: h["P01A",2] |> plot(stem_label=TRUE, leaf_label=TRUE)h <- atctree(schema="full") #more useful to use the full tree with this approach # plot descendents of P01 (as far as grandchildren): h["P01",-2] |> plot(stem_label=TRUE, leaf_label=TRUE) # plot descendents of P01 (as far as great grandchildren): h["P01",-3] |> plot(stem_label=TRUE, leaf_label=FALSE) # plot descendents of parent of P01A: h["P01A",1] |> plot(stem_label=TRUE, leaf_label=TRUE) # plot descendents of grandparent of P01A: h["P01A",2] |> plot(stem_label=TRUE, leaf_label=TRUE)
This contains nodes of the ATC hierarchy at all 5 levels (e.g. A, A01, A01A ...), and associated descriptive text (eg. for A: ALIMENTARY TRACT AND METABOLISM), used here for visualisation.
ATCdataATCdata
A named character vector for each node, where each entry is an ATC code and the name is a textual description
The ATC data can be perused at <https://atcddd.fhi.no/atc_ddd_index/>.
This data is from the repository at <https://github.com/fabkury/atcd> and this release is at <https://github.com/fabkury/atcd/releases/tag/april2026>.
The first two columns from the .csv file were selected to produce the named character vector
constructor for atctree objects
atctree( whichlevs = NULL, schema = c("none", "full", "anatomical", "therapeutic", "chemical") )atctree( whichlevs = NULL, schema = c("none", "full", "anatomical", "therapeutic", "chemical") )
whichlevs |
subset of levels to use from integers 1:5 |
schema |
a conceptual subset of the ATC hierarchy, or all of it ('full'), or something bespoke ('none') |
either schema or whichlevs should be specified; (e.g. 'schema=full' corresponds to 'whichlevs=1:5')
an object of class atctree
h <- atctree(schema="anatomical") # tree will contain levels 1 and 5 h <- atctree(whichlevs=c(1,2,5)) # bespoke structureh <- atctree(schema="anatomical") # tree will contain levels 1 and 5 h <- atctree(whichlevs=c(1,2,5)) # bespoke structure
class to represent a tree from the ATC hierarchy
nodenode id
pnodeparent node id
labATC code
plabparent ATC code
textATC textual info
drugnamescommon names for drugs where known
levlevel of each node (root node is 0)
schemaone of 'none', 'full', 'anatomical', 'therapeutic', 'chemical'
whichlevssubset of integers 1:5; should correspond to schema
Nnodenumber of nodes in the tree excluding root node
Nlevnumber of levels in the tree excluding root node
Cut out a branch with just the descendants of the specified node.
This will include the direct parent of the specified node as information - this is also useful for grafting.
## S4 method for signature 'atctree' cutting(h, nodelabel = NULL)## S4 method for signature 'atctree' cutting(h, nodelabel = NULL)
h |
an object of class atctree |
nodelabel |
identify node of interest |
returns a (smaller) object of class atctree
h <- atctree(schema="therapeutic") # Suppose we are interested in a branch of this tree; take a cutting and plot it: cutting(h, "P01") |> plot() # a different look: cutting(h, "P01") |> plot(text_angle=0, circle=TRUE)h <- atctree(schema="therapeutic") # Suppose we are interested in a branch of this tree; take a cutting and plot it: cutting(h, "P01") |> plot() # a different look: cutting(h, "P01") |> plot(text_angle=0, circle=TRUE)
display drug name for ATC codes
drugnames(x)drugnames(x)
x |
vector of ATC codes |
character vector of drug names
graft (combine) trees
## S4 method for signature 'atctree,atctree' graft(h1, h2, ...)## S4 method for signature 'atctree,atctree' graft(h1, h2, ...)
h1 |
an atctree |
h2 |
an atctree |
... |
more atctree objects |
Trees are grafted together at the root so they can be displayed on the same figure At the moment the branches need to be of the same schema/have the same levels
an object of class atctree
# some nodes involving inflammation from look(h, "inflamm") h <- atctree(schema="full") h1 <- cutting(h, "M01") h2 <- cutting(h, "A07") graft(h1,h2) |> plot(circle=TRUE, leaf=FALSE) h1 <- h["P01",-3] #P01 to great grandchildren h2 <- h["C01",-1] #C01 to children h3 <- cutting(h, "G01A") #descendents of G01A graft(h1, h2, h3) |> plot(stem_label=TRUE)# some nodes involving inflammation from look(h, "inflamm") h <- atctree(schema="full") h1 <- cutting(h, "M01") h2 <- cutting(h, "A07") graft(h1,h2) |> plot(circle=TRUE, leaf=FALSE) h1 <- h["P01",-3] #P01 to great grandchildren h2 <- h["C01",-1] #C01 to children h3 <- cutting(h, "G01A") #descendents of G01A graft(h1, h2, h3) |> plot(stem_label=TRUE)
search the node texts for an expression
## S4 method for signature 'atctree' look(h, txt)## S4 method for signature 'atctree' look(h, txt)
h |
an object of class atctree |
txt |
word or part of a word or regular expression to search for |
returns a vector of nodes whose text matches
h <- atctree(schema="full") nds <- look(h, "inflamm") # a search for inflammatory substances and families # plot element nds[1] which is "A07E": cutting(h, nds[1]) |> plot()h <- atctree(schema="full") nds <- look(h, "inflamm") # a search for inflammatory substances and families # plot element nds[1] which is "A07E": cutting(h, nds[1]) |> plot()
show the parents for the specified node(s) in the tree
## S4 method for signature 'atctree' parents(h, node, anc = 1)## S4 method for signature 'atctree' parents(h, node, anc = 1)
h |
tree the node belongs to |
node |
a node e.g. A01AX |
anc |
level of ancestry (default 1). How many generations back or forward? |
atctree object
show the parents for the specified node(s) in the full tree
## S4 method for signature 'character' parents(h)## S4 method for signature 'character' parents(h)
h |
node(s) |
parent node(s)
parents(c("A01AA","A01","A"))parents(c("A01AA","A01","A"))
plot the tree as a network graph
## S4 method for signature 'atctree' plot( x, circle = NULL, ATC_text = NULL, leaf_label = NULL, stem_label = NULL, include_names = F, text_size = 10, text_angle = 45, width = 500, height = 500, hover_msg = TRUE )## S4 method for signature 'atctree' plot( x, circle = NULL, ATC_text = NULL, leaf_label = NULL, stem_label = NULL, include_names = F, text_size = 10, text_angle = 45, width = 500, height = 500, hover_msg = TRUE )
x |
an object of class atctree |
circle |
whether or not to arrange graph over a circle |
ATC_text |
whether or not to label with ATC textual info |
leaf_label |
whether or not leaf nodes will be labelled |
stem_label |
whether or not stem nodes will be labelled |
include_names |
whether or not to include common names in text |
text_size |
annotation text size |
text_angle |
annotation text angle |
width |
graph width |
height |
graph height |
hover_msg |
whether to remind the user that they can hover over nodes |
Each node is labelled with its ATC code, and by hovering the cursor over any node the ATC desciption is displayed. The ATC tree can be displayed as a network in layers or on a circle (with radii corresponding to ATC level). It is evident that a plot the full ATC tree is too cluttered. Some subsetting (link), pruning (link) or cutting (link) of the tree is likely to help visualisation.
No return value, called for side effects
# create an ATC tree and plot the whole thing: h <- atctree(schema="full") # you could plot this with plot(h) but it takes a while # large network so not easy to read # take cutting above node B ; plot all its descendants: cutting(h,"B") |> plot() # plot node B down to its grandchildren: h["B",-2] |> plot() # or use a circular layout h["B",-2] |> plot(circle=TRUE, stem_label=TRUE)# create an ATC tree and plot the whole thing: h <- atctree(schema="full") # you could plot this with plot(h) but it takes a while # large network so not easy to read # take cutting above node B ; plot all its descendants: cutting(h,"B") |> plot() # plot node B down to its grandchildren: h["B",-2] |> plot() # or use a circular layout h["B",-2] |> plot(circle=TRUE, stem_label=TRUE)
Pruning is specifying the removal of some unwanted branch of the tree (in contrast to taking a cutting, where it is the branch which is kept).
## S4 method for signature 'atctree' pruning(h, nodelabels = NULL)## S4 method for signature 'atctree' pruning(h, nodelabels = NULL)
h |
an object of class atctree |
nodelabels |
character vector of nodes of interest |
a (smaller) object of class atctree
library(visATC) h1 <- atctree(whichlevs=1:3) h1A <- cutting(h1, "C") # make a subtree cut at node C plot(h1A, circle=TRUE) # suppose we decide not to display some nodes: pruning(h1A, c("C01", "C05", "C10")) |> plot(circle=TRUE)library(visATC) h1 <- atctree(whichlevs=1:3) h1A <- cutting(h1, "C") # make a subtree cut at node C plot(h1A, circle=TRUE) # suppose we decide not to display some nodes: pruning(h1A, c("C01", "C05", "C10")) |> plot(circle=TRUE)
shows schema, number of nodes and levels and a cross-table, excluding the root node.
## S4 method for signature 'atctree' show(object)## S4 method for signature 'atctree' show(object)
object |
of class acttree |
prints summary to console
h <- atctree(whichlevs=1:4) (h)h <- atctree(whichlevs=1:4) (h)
treelevs: return levels within tree (excluding 0)
leaves: return labels of terminal elements (leaves) of tree
nlevs: number of levels in tree (excluding 0)
## S4 method for signature 'atctree' treelevs(h) ## S4 method for signature 'atctree' leaves(h) ## S4 method for signature 'atctree' nlevs(h)## S4 method for signature 'atctree' treelevs(h) ## S4 method for signature 'atctree' leaves(h) ## S4 method for signature 'atctree' nlevs(h)
h |
an object of class atctree |
a vector of the level of each node
vector of labels of the leaf nodes
vector of number of levels in the tree