Package 'visATC'

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

Help Index


find a subset of the tree

Description

find a subset of the tree

Usage

## S4 method for signature 'atctree'
x[i, j = 1L]

Arguments

x

object of class atctree

i

label (ATC code) of focal node

j

generation (integer). 0: siblings, -1: children, -2: grandchildren, 1: parents etc

Details

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.

Value

an object of class atctree

Examples

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)

nodes of the ATC hierarchy

Description

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.

Usage

ATCdata

Format

A named character vector for each node, where each entry is an ATC code and the name is a textual description

Source

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

Description

constructor for atctree objects

Usage

atctree(
  whichlevs = NULL,
  schema = c("none", "full", "anatomical", "therapeutic", "chemical")
)

Arguments

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')

Details

either schema or whichlevs should be specified; (e.g. 'schema=full' corresponds to 'whichlevs=1:5')

Value

an object of class atctree

Examples

h <- 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

Description

class to represent a tree from the ATC hierarchy

Slots

node

node id

pnode

parent node id

lab

ATC code

plab

parent ATC code

text

ATC textual info

drugnames

common names for drugs where known

lev

level of each node (root node is 0)

schema

one of 'none', 'full', 'anatomical', 'therapeutic', 'chemical'

whichlevs

subset of integers 1:5; should correspond to schema

Nnode

number of nodes in the tree excluding root node

Nlev

number of levels in the tree excluding root node


cutting from an ATC tree

Description

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.

Usage

## S4 method for signature 'atctree'
cutting(h, nodelabel = NULL)

Arguments

h

an object of class atctree

nodelabel

identify node of interest

Value

returns a (smaller) object of class atctree

Examples

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

Description

display drug name for ATC codes

Usage

drugnames(x)

Arguments

x

vector of ATC codes

Value

character vector of drug names


graft (combine) trees

Description

graft (combine) trees

Usage

## S4 method for signature 'atctree,atctree'
graft(h1, h2, ...)

Arguments

h1

an atctree

h2

an atctree

...

more atctree objects

Details

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

Value

an object of class atctree

Examples

# 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

Description

search the node texts for an expression

Usage

## S4 method for signature 'atctree'
look(h, txt)

Arguments

h

an object of class atctree

txt

word or part of a word or regular expression to search for

Value

returns a vector of nodes whose text matches

Examples

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

Description

show the parents for the specified node(s) in the tree

Usage

## S4 method for signature 'atctree'
parents(h, node, anc = 1)

Arguments

h

tree the node belongs to

node

a node e.g. A01AX

anc

level of ancestry (default 1). How many generations back or forward?

Value

atctree object


show the parents for the specified node(s) in the full tree

Description

show the parents for the specified node(s) in the full tree

Usage

## S4 method for signature 'character'
parents(h)

Arguments

h

node(s)

Value

parent node(s)

Examples

parents(c("A01AA","A01","A"))

plot the tree as a network graph

Description

plot the tree as a network graph

Usage

## 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
)

Arguments

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

Details

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.

Value

No return value, called for side effects

Examples

# 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)

prune an ATC tree

Description

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).

Usage

## S4 method for signature 'atctree'
pruning(h, nodelabels = NULL)

Arguments

h

an object of class atctree

nodelabels

character vector of nodes of interest

Value

a (smaller) object of class atctree

Examples

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)

summarise atctree object

Description

shows schema, number of nodes and levels and a cross-table, excluding the root node.

Usage

## S4 method for signature 'atctree'
show(object)

Arguments

object

of class acttree

Value

prints summary to console

Examples

h <- atctree(whichlevs=1:4)
(h)

helper functions for atctrees

Description

treelevs: return levels within tree (excluding 0)

leaves: return labels of terminal elements (leaves) of tree

nlevs: number of levels in tree (excluding 0)

Usage

## S4 method for signature 'atctree'
treelevs(h)

## S4 method for signature 'atctree'
leaves(h)

## S4 method for signature 'atctree'
nlevs(h)

Arguments

h

an object of class atctree

Value

a vector of the level of each node

vector of labels of the leaf nodes

vector of number of levels in the tree