Package 'halfcircle'

Title: Plot Halfcircle Diagram
Description: There are growing concerns on flow data in diverse fields including trade, migration, knowledge diffusion, disease spread, and transportation. The package is an effective visual support to learn the pattern of flow which is called halfcircle diagram. The flow between two nodes placed on the center line of a circle is represented using a half circle drawn from the origin to the destination in a clockwise direction. Through changing the order of nodes, the halfcircle diagram enables users to examine the complex relationship between bidirectional flow and each potential determinants. Furthermore, the halfmeancenter function, which calculates (un) weighted mean center of half circles, makes the comparison easier.
Authors: Sohyun Park, Ningchuan Xiao
Maintainer: Sohyun Park <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-01-19 03:44:48 UTC
Source: https://github.com/cran/halfcircle

Help Index


Traded volume of land between countries

Description

A dataset containing trade data between countries and traded volumes for each 4 category.

Usage

data(ex_flow)

Format

A data frame with 10866 rows and 6 variables:

O

name of exporting country

D

name of importing country

vegetable

volume of land associated with trading vegetables, in ha

fruit

volume of land associated with trading fruits, in ha

wheat

volume of land associated with trading wheats, in ha

soybean

volume of land associated with trading soybeans, in ha

Source

http://fao.org/faostat/


country attributes

Description

A dataset containing 154 countries who participate in the trade and related attributes.

Usage

data(ex_node)

Format

A data frame with 154 rows and 8 variables:

country

name of exporting country

x

longitude of the center of a country

y

latitude of the center of a country

pop_total

total number of population

gdpc

Gross Domestic Product per capita, in dollar

area_cultivation

total volume land for cultivation use, in ha

water_total

total volume of usable water, in cubic meter

income_level

5 levels by income

Source

http://fao.org/faostat/


Visualization method for flow data using halfcircle diagram

Description

halfcircle function draws flows between nodes creating halfcircle diagram.

Usage

halfcircle(flow, node, dir = "horizontal", circle.col = "lightgray",
  circle.trans = 0.5, flow.col = "black", flow.trans = 0.5,
  flow.width = "proportional", node.color = "black", node.size = 0.1,
  node.pch = 20, node.trans = 0.7, label = node[, c(1)],
  label.size = 0.5, label.col = "black", label.gap = 0.1)

Arguments

flow

a dataframe which is to draw half-circles. The data should be in the form of an edge list containing node of origin, node of destination, and magnitude of the flow on the first three columns.

node

a dataframe which contains names of node on the first column. Nodes on the center line of a circle are drawn by the order of the data. Every node presented in flow data must be contained.

dir

if 'horizontal' (the default), nodes are drawn along the X-axis. If 'vertical', nodes are drawn along the Y-axis.

circle.col

color of background circle

circle.trans

transparency of color of background circle

flow.col

flow color. flow.col can be a list of color vectors, the vectors are then used per flow.

flow.trans

transparency of color of flows

flow.width

width of flows. if 'proportional' (the default), each width is calculated to be proportional to the maximum volume of flows. Maximum width is set to be 10. Otherwise, a list of width vectors can be used per flow.

node.color

node color. It can be a list of color vectors, and the vectors are then used per node.

node.size

node size

node.pch

node type. see ?points for more options.

node.trans

transparency of color of flows

label

the first column of node, names, is represented (the default). a list of vector an be used per node. if NULL, no label is drawn.

label.size

label size

label.col

label color

label.gap

gap between the node and the respective label

Details

This function is a low-level graphical function, and you will create a halfcircle diagram. To create the diagram, nodes are placed as a set of points on a straight line segment in the center of a circle. The flow between two nodes is represented using a half cicle drawn from the origin to the destination in a clockwise direction. It is virtually drawn on xy-coordinates where both x and y range from -1 to 1. Flows between the same nodes are not drawn.

Author(s)

Sohyun Park <[email protected]>, Ningchuan Xiao

References

Xiao and Chun (2009) <doi:10.1559/152304009788188763>

Examples

# load flow data
data(ex_flow)
flow <- ex_flow[,c(1,2,3)] # select veget column as volume
flow <- subset(flow,flow$vegetable>5000)
data(ex_node) # load node data
node <- ex_node[c(order(-ex_node$gdpc)),] # sort nodes in descending order of gdpc values
halfcircle(flow, node, dir="vertical", circle.col="gray", flow.col="black",label=NULL)

# legend
max <- max(flow[,c(3)]); median <- median(flow[,c(3)]); min <- min(flow[,c(3)])
max_w <- 10; median_w <- round(10*median/max); min_w <- round(10*min/max)
legend(x=-1.2, y=-0.8, legend=c(paste(round(max)), paste(round(median)), paste(round(min))),
    lty=1, lwd=c(max_w, median_w, min_w), cex=0.7)

# customize colors
node$color <- c("#22abcb","#4eb6ad","#86c388","#adcd6c","#dad84f")[node$income_level]
flow2 <- data.frame(flow, node[match(flow[,"O"], node[,"country"]),])
halfcircle(flow2, node, dir="vertical", flow.col=flow2$color, node.color=node$color, label=NULL)

# highlight one node
flow3 <- flow
flow3$color <- "gray"
flow3$color[flow3$O=="China"|flow3$D=="China"] <- "blue"
flow3 <- flow3[c(order(flow3$color,decreasing=TRUE)),]
node$label <- ""
node$label[node$country=="China"] <- "China"
halfcircle(flow3, node, dir="vertical", flow.col=flow3$color, label=node$label, label.size=0.7)

Calculate average values of flows and plot them

Description

Calculate average values of flows and plot them

Usage

halfmeancenter(flow, node, dir = "horizontal")

Arguments

flow

a dataframe which is to draw half-circles. The data should consist of node of origin, node of destination, and magnitude of the flow on the first three columns.

node

a dataframe which contains names of node on the first column. Nodes on the center line of a circle are drawn by the order of the data.

dir

if 'horizontal', nodes are drawn along the X-axis. If 'vertical', nodes are drawn along the Y-axis.

Details

This function is to get values of mean centers and average radius of flows. One of values of mean centers is weighted by the magnitude of flow and the other one is unweighted. If flows are normally distributed or all combinations of flows between nodes are made, the mean center should be located in the center of a circle, that is (0,0) on the xy-coordinates, and average radius should be 0.5. If the mean center fall in a certain quadrant, a user can evaluate the skewedness.

Value

A list containing calculated average values c(x-coordinate of weighted mean center, y-coordinate of weighted mean center, weighted average radius,x-coordinate of unweighted mean center, y-coordinate of unweighted mean center, unweighted average radius)

Author(s)

Sohyun Park <[email protected]>, Ningchuan Xiao

Examples

data(ex_flow)
flow <- subset(ex_flow, ex_flow$veget>5000)
data(ex_node)
node <- ex_node[c(order(-ex_node$gdpc)),]
halfmeancenter(flow, node, dir="vertical")