R example
Overview
Figlinq is compatible with Plotly's R API, and you can use the plotly package to interact with content on Figlinq. This simple example illustrates how you can use this package to create a simple line chart and save it, together with associated data, to your Figlinq account.
API key and username
To connect to your Figlinq account, you will need to provide your username and API key. You can find both in your account page. There, you can also create a new API key if needed.
Privacy settings
By default, all plots and data grids created with the R API are currently public. Make sure to override this setting by including the config parameter sharing = "private" in the api_create function.
Example
# Install and load required libraries
install.packages("plotly") # If not already installed
library(plotly)
# Set credentials
Sys.setenv("plotly_username" = "YOUR_USER_NAME")
Sys.setenv("plotly_api_key" = "YOUR_API_KEY")
Sys.setenv("plotly_domain"="https://create.figlinq.com")
# Create data frame
data <- data.frame(
x = c(1, 2, 3, 4),
y0 = c(10, 15, 13, 17),
y1 = c(16, 5, 11, 9)
)
# Create plot and add traces
fig <- plot_ly(data, width = 400, height = 360)
fig <- fig %>% add_lines(x = ~x, y = ~y0, name = "Trace 0")
fig <- fig %>% add_lines(x = ~x, y = ~y1, name = "Trace 1")
# Set some basic plot styling
fig <- fig %>% layout(
margin = list(t = 60),
autosize = FALSE,
plot_bgcolor = "white",
title = list(
text = "Example plot from R!",
x = 0.5,
xanchor = "center",
yanchor = "top"
),
xaxis = list(
showgrid = FALSE,
title = "X Axis",
titlefont = list(size = 14),
tickfont = list(size = 14),
linewidth = 1,
linecolor = "black",
ticklen = 5,
ticks = "outside"
),
yaxis = list(
showgrid = FALSE,
title = "Y Axis",
titlefont = list(size = 14),
tickfont = list(size = 14),
linewidth = 1,
linecolor = "black",
ticklen = 5,
ticks = "outside"
)
)
api_create(fig, filename = "Plot from R", sharing = "private")
Result
- After running the script, your default browser will open the newly-created plot in view mode.
- If you receive a 404 error after the browser opens, you are likely not logged in. Please make sure that you are logged in to your Figlinq account in your default browser before running the script.
- The newly-created plot and data grid will be available in your home directory - from there, you can move them to other folders, edit, restyle, add to a figure, or share.
- If you run the script multiple times without changing the filename, the plot and grid will be overwritten.
api_create Function
Overview
The api_create
function in the R plotly library is used to create and upload interactive Plotly graphs directly from R. This function facilitates the process of creating and sharing high-quality, interactive visualizations in Figlinq.
Signature
library(plotly)
api_create(plot, filename = NULL, fileopt = "overwrite", sharing = "public", origin = "plot")
Input Arguments
plot
: A Plotly object (plotly, ggplotly, or subplot object) to be uploaded or updated in Figlinq.filename
(Optional, Default:NULL
): A character string specifying the filename for the plot. If set toNULL
, a default filename will be generated.fileopt
(Optional, Default:"overwrite"
): A character string specifying the file option. Accepted values are:"overwrite"
: Overwrites the file with the same filename if it exists."append"
: Appends the new plot to an existing file with the same filename."new"
: Creates a new file with the given filename. If a file with the same name exists, a numeric suffix will be added.
sharing
(Optional, Default:"public"
): A character string specifying the sharing setting for the plot. Accepted values are:"public"
: The plot is publicly accessible."private"
: The plot is private and can only be accessed by the owner."secret"
: The plot is private and can be accessed by anyone with the URL, but it won't be listed on the owner's profile.
origin
(Optional, Default:"plot"
): A character string specifying the origin of the plot. Accepted values are:"plot"
: Indicates that the plot is created using theplotly
package."ggplot"
: Indicates that the plot is created using theggplotly
package.