1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/set_node_position.R 3\name{set_node_position} 4\alias{set_node_position} 5\title{Apply a layout position to a single node} 6\usage{ 7set_node_position(graph, node, x, y, use_labels = FALSE) 8} 9\arguments{ 10\item{graph}{A graph object of class \code{dgr_graph}.} 11 12\item{node}{A single-length vector containing either a node ID value 13(integer) or a node label (character) for which position information should 14be applied.} 15 16\item{x}{The x coordinate to set for the node.} 17 18\item{y}{The y coordinate to set for the node.} 19 20\item{use_labels}{An option to use a node \code{label} value in \code{node}. Note that 21this is only possible if all nodes have distinct \code{label} values set and 22none exist as an NA value.} 23} 24\value{ 25A graph object of class \code{dgr_graph}. 26} 27\description{ 28Apply position information for a single node. This is done by setting the \code{x} 29and \code{y} attrs for a node \code{id} or node \code{label} supplied in \code{node}. When 30rendering the graph, nodes with attribute values set for \code{x} and \code{y} will be 31fixed to those positions on the graph canvas. 32} 33\examples{ 34# Create a simple graph with 4 nodes 35graph <- 36 create_graph() \%>\% 37 add_node(label = "one") \%>\% 38 add_node(label = "two") \%>\% 39 add_node(label = "three") \%>\% 40 add_node(label = "four") 41 42# Add position information to each of 43# the graph's nodes 44graph <- 45 graph \%>\% 46 set_node_position( 47 node = 1, 48 x = 1, y = 1) \%>\% 49 set_node_position( 50 node = 2, 51 x = 2, y = 2) \%>\% 52 set_node_position( 53 node = 3, 54 x = 3, y = 3) \%>\% 55 set_node_position( 56 node = 4, 57 x = 4, y = 4) 58 59# View the graph's node data frame to 60# verify that the `x` and `y` node 61# attributes are available and set to 62# the values provided 63graph \%>\% get_node_df() 64 65# The same function can modify the data 66# in the `x` and `y` attributes 67graph <- 68 graph \%>\% 69 set_node_position( 70 node = 1, 71 x = 1, y = 4) \%>\% 72 set_node_position( 73 node = 2, 74 x = 3, y = 3) \%>\% 75 set_node_position( 76 node = 3, 77 x = 3, y = 2) \%>\% 78 set_node_position( 79 node = 4, 80 x = 4, y = 1) 81 82# View the graph's node data frame 83graph \%>\% get_node_df() 84 85# Position changes can also be made by 86# supplying a node `label` value (and setting 87# `use_labels` to TRUE). For this to work, 88# all `label` values in the graph's ndf must 89# be unique and non-NA 90graph <- 91 graph \%>\% 92 set_node_position( 93 node = "one", 94 x = 1, y = 1, 95 use_labels = TRUE) \%>\% 96 set_node_position( 97 node = "two", 98 x = 2, y = 2, 99 use_labels = TRUE) 100 101# View the graph's node data frame 102graph \%>\% get_node_df() 103} 104\seealso{ 105Other Node creation and removal: 106\code{\link{add_n_node_clones}()}, 107\code{\link{add_n_nodes_ws}()}, 108\code{\link{add_n_nodes}()}, 109\code{\link{add_node_clones_ws}()}, 110\code{\link{add_node_df}()}, 111\code{\link{add_nodes_from_df_cols}()}, 112\code{\link{add_nodes_from_table}()}, 113\code{\link{add_node}()}, 114\code{\link{colorize_node_attrs}()}, 115\code{\link{copy_node_attrs}()}, 116\code{\link{create_node_df}()}, 117\code{\link{delete_nodes_ws}()}, 118\code{\link{delete_node}()}, 119\code{\link{drop_node_attrs}()}, 120\code{\link{join_node_attrs}()}, 121\code{\link{layout_nodes_w_string}()}, 122\code{\link{mutate_node_attrs_ws}()}, 123\code{\link{mutate_node_attrs}()}, 124\code{\link{node_data}()}, 125\code{\link{recode_node_attrs}()}, 126\code{\link{rename_node_attrs}()}, 127\code{\link{rescale_node_attrs}()}, 128\code{\link{set_node_attr_to_display}()}, 129\code{\link{set_node_attr_w_fcn}()}, 130\code{\link{set_node_attrs_ws}()}, 131\code{\link{set_node_attrs}()} 132} 133\concept{Node creation and removal} 134