Exploring bar charts with negative values using Dygraph in R

I have time-series data that I want to visualize in R using dygraphs with bars instead of lines. I found a custom plotter function on the dygraphs documentation and tried implementing it:

dyBarChart <- function(dygraph) {
  dyPlotter(dygraph = dygraph,
            name = "BarChart",
            path = system.file("plotters/barchart.js",
                               package = "dygraphs"))
}

The issue arises when dealing with negative values.
The following line plot works fine with the dygraph() function:

dygraph(test)

https://i.sstatic.net/LBv0Om.png

However, when attempting to add the bar chart, nothing is plotted and warnings are generated:

dygraph(z)  %>%  dyBarChart() 
There were 14 warnings (use warnings() to see them)
> warnings()

Warning messages:
1: In normalizePath(path) : path[1]="": No such file or directory
2: In file.copy(from, to, overwrite = TRUE, recursive = isdir) : too deep nesting
3: In file.copy(from, to, overwrite = TRUE, recursive = isdir) : too deep nesting...

Are there any known solutions for displaying negative values in R dygraph barcharts?

Here is the sample data provided:

> dput(test)
structure(c(-6L, 0L, -4L, -1L, 2L, 0L, 18L, -3L, -2L, -1L, -2L, 
1L, -22L, -5L, -1L, 3L, 11L, 2L, -2L, 5L, -3L, -1L, -2L, 0L, 
12L), index = structure(c(1521217200, 1521217800, 1521218400, 
1521219000, 1521219600, 1521220200, 1521220800, 1521221400, 1521222000, 
1521222600, 1521223200, 1521223800, 1521224400, 1521225000, 1521225600, 
1521226200, 1521226800, 1521227400, 1521228000, 1521228600, 1521229200, 
1521229800, 1521230400, 1521231000, 1521231600), class = c("POSIXct", 
"POSIXt"), tzone = ""), class = "zoo")

Answer №1

After testing the example from the link provided, it became clear that it was not functioning properly. Fortunately, a solution was found in this post on Stack Overflow: How do you create a bar and line plot with R dygraphs?

Below is the corrected dyBarChart function that will make your code work as intended.

dyBarChart <- function(dygraph) {
    dyPlotter(
        dygraph = dygraph,
        name = "BarChart",
        path = system.file("examples/plotters/barchart.js", package = "dygraphs")
    )
}

dygraph(test) %>% dyBarChart()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

TS type defined by JS constants

I am currently working on a project that involves both JavaScript and TypeScript. I am trying to find a solution to reduce code duplication when using JavaScript string constants by converting them into TypeScript types. For example, let's say I have ...

Delete a Woocommerce item from the shopping cart using ajax/fetch technology

My issue lies with the removal of products from the cart in Woocommerce, specifically involving WC_Cart::remove_cart_item. The error messages I am encountering are: POST http://localhost:3000/esport/wp-admin/admin-ajax.php [HTTP/1.1 500 Internal Server Err ...

Executing JavaScript Function on the Server Side

Recently, I created a JavaScript function that looks like this: function ShowMsg(msg) { $.blockUI({ message: '<div dir=rtl align=center><h1><p>' + msg + '</p></h1></div>', css: { ...

How can I programmatically trigger the opening of a Material-UI Accordion in ReactJS?

All of the Accordions are assigned unique IDs: const CategoryDisplay: React.FC<Props> = (props) => { ... return ( <> <Accordion id={`category-${accordion.id}`}/> </> ); }; export default CategoryDisplay ...

What is the best way to navigate to a specific location on a web page?

After clicking the "Add comment" link, a comment form popped up using Ajax. I now need assistance with scrolling to it, can you please help me out? ...

Access Vuex Getters in a separate JavaScript file

Within the file /store/user/getters.js: function getLoggedIn (state) { return state.loggedIn } In a different file, router-auth.js, I attempted to access the value (true or false) of getters.getLoggedIn in the following manner: import user from '.. ...

Step-by-step guide on uploading an image to Cloudinary using the MERN stack

Encountered an error when trying to submit the form: POST 400 (Bad Request) {"error":{"message":"Upload preset must be whitelisted for unsigned uploads"}} form.jsx const uploadImageToCloudinary = async (imageFile) => { ...

The Next.js React app is constantly loading without any interruptions

Just diving into Next.js and attempting to transform a single HTML page into a Next.js website in order to integrate sanity. Managed to import all necessary assets, but stuck with the persistent preloader issue. After inspecting elements, noticed that a fi ...

Using NodeJS to convert a Base64 string into a JPEG image with the help of either NodeJS or

I have successfully stored a JPEG image in my MySQL database using the longblob format. Now, when I retrieve the longblob data, I am only getting a base64 string. How can I convert this base64 string back to a readable JPEG image using MySQL or Node.js? B ...

I am having trouble adding a second image. The functionality only seems to work for the first image input

How come I can't access the second file chooser when the first one works perfectly fine? This section contains HTML code <form action="<?php url("image/uploadImg"); ?>" method="post" en ...

Cease an if condition in AngularJS JavaScript

I am facing a situation where I have an if statement that needs to halt execution but only after certain processes have been completed. This if statement is enclosed within a forEach loop in an Angular context. angular.forEach($scope.obj, function ( val ...

Encountering issues with parsing normals in THREE.js json mesh format

UPDATE: The demo is finally live! Check it out here: . Use the dropdown menu to switch between torus models and see the issue in action. Please note that WebGL MRT extensions are required for this demo. I have been working on developing my own WebGL defer ...

What could be causing the Vue data to fail to update in this particular scenario?

I'm having trouble grasping Vue completely. For example, consider the following code snippets: <!--store.js--> export default { x:{ p:{}, }, } <!--text.vue--> <template> <div class="test-comp">Test componen ...

Having trouble launching the react app with npm start command

Attempting to launch a react app created by someone else. The instructions provided stated that in order to start it, I need to follow these steps To initiate the webpack dev script, execute npm start [appname]. The term [appname] corresponds to an appli ...

When selecting a different file after initially choosing one, the Javascript file upload event will return e.target as null

Currently, I have implemented file uploading using <input>. However, when attempting to change the file after already selecting one, the website crashes and states that event.target is null. <Button label="Upload S3 File"> <input ...

Error: Unable to access undefined properties (attempting to read 'getBoundingClientRect')

I keep encountering the issue TypeError: Cannot read properties of undefined (reading 'getBoundingClientRect') while working in React on my localhost with Node.js. I can't figure out what's causing it. import React,{useRef,useState} fro ...

When dragging a new connection in jsPlumb, the existing one should be automatically removed

After using jsPlumb, I was able to create a setup with the following features: Multiple nodes functioning like nodes in a unique flowchart design. Each node has a single target where connections can be dropped. Every node has zero, one, or more exits. Ea ...

The NODE.JS application becomes unresponsive when attempting to retrieve 2.5 million records from an API

I'm facing an issue where my app is retrieving millions of rows from a database and API, causing it to get stuck after calling the getData() function. let closedOrdersStartDate; preparedOrdersPromise = tickApiConnector.obtainT ...

What is the best way to reposition the caret within an <input type="number"> element?

How can I make the caret move when an input is clicked? The code I found works with text, but not with number. Also, is there a way to pass the length without specifying a value (e.g. 55) in the parameters? HTML <input type="number" name="cost" value= ...

Implementing conditional statements in Puppeteer web scraping

Attempting to extract data from a table... Each country name is wrapped in an <a> tag, however some are not. Unfortunately, when the structure of the HTML changes, the program crashes Code => https://i.sstatic.net/zW3Cd.png Output => https: ...