Creating a plot with primary and secondary axis

deepeshj
deepeshj New Altair Community Member
edited November 2024 in Community Q&A
Hello All,

I am trying to create a plot that combines the volume in various categories as a bar plot (on the primary axis). I want to superimpose a line chart with the rates, but on the secondary axis. I do not see any option to plot the additional chart on the secondary axis. 

Please help if this at all can be done within RM.

Thanks!!

Best Answer

  • varunm1
    varunm1 New Altair Community Member
    edited September 2019 Answer ✓
    Hello @deepeshj

    I am sure what you are asking can be done in RM visualizations. I assume you are looking to get two Y-axis opposite to each other rather than, single y-axis with two (If this is the case @gopala solutions works well)  this is what I am thinking based on your question relating to the axis. The left y-axis is primary and the right y-axis is secondary.


    This can be done as well, follow the below steps.
    1. Add a plot similar to gopala suggestion. And select the relevant X-axis and Y-axis



    2. Now you need to add a new y-axis, scroll down and you will find y-axis, expand it. Click on add new y-axis as shown in the left figure and then change the axis style of y2 axis based on right side image, click on axis style and select opposite. 



    3. Finally, you need to link this y2 to plot 2 as shown below. If you scroll up, you can see plot 2 and option linked Y-axis where you need to change the default y1 to y2 in plot 2.



    4. The final plot for titanic training data set with Age in the x-axis, No of siblings on y1 axis (Primary) and Passenger fare on y2 axis (Secondary).



    Hope this helps.

Answers

  • arjun_gopal
    arjun_gopal New Altair Community Member
    Hi Deepesh, 
    You can use "Add new plot" as shown below, hope it helps.



  • varunm1
    varunm1 New Altair Community Member
    edited September 2019 Answer ✓
    Hello @deepeshj

    I am sure what you are asking can be done in RM visualizations. I assume you are looking to get two Y-axis opposite to each other rather than, single y-axis with two (If this is the case @gopala solutions works well)  this is what I am thinking based on your question relating to the axis. The left y-axis is primary and the right y-axis is secondary.


    This can be done as well, follow the below steps.
    1. Add a plot similar to gopala suggestion. And select the relevant X-axis and Y-axis



    2. Now you need to add a new y-axis, scroll down and you will find y-axis, expand it. Click on add new y-axis as shown in the left figure and then change the axis style of y2 axis based on right side image, click on axis style and select opposite. 



    3. Finally, you need to link this y2 to plot 2 as shown below. If you scroll up, you can see plot 2 and option linked Y-axis where you need to change the default y1 to y2 in plot 2.



    4. The final plot for titanic training data set with Age in the x-axis, No of siblings on y1 axis (Primary) and Passenger fare on y2 axis (Secondary).



    Hope this helps.
  • deepeshj
    deepeshj New Altair Community Member
    Hi @gopala- I was able to create charts of the type you shared but this wasn't what I was looking for. May be my question wasn't clear. Anyways, thanks!!
  • deepeshj
    deepeshj New Altair Community Member
    Hi @varunm1- This is exactly what I was trying to create. Thanks a lot!!