+ Reply to Thread
Results 1 to 11 of 11

Finding data and plotting a scatter chart with VBA

  1. #1
    Registered User
    Join Date
    10-04-2017
    Location
    London, UK
    MS-Off Ver
    2010
    Posts
    5

    Finding data and plotting a scatter chart with VBA

    Hi, I was hoping someone could help me with the problem I've been facing - I would need to plot the scatter chart for several groups, however, the problem is that the number of constituents, within these groups, vary. I have attached an excel file with the potential outcome I have in mind. I would be grateful if someone could help me with this
    Attached Files Attached Files

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Finding data and plotting a scatter chart with VBA

    Hi,

    Using the dataset you provided as an example, you could define named ranges for each of the groups' x and y values like so:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then plot the named ranges in the chart,

    X Values = Sheet1!aaa_x
    Y Values = Sheet1!aaa_y
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    10-04-2017
    Location
    London, UK
    MS-Off Ver
    2010
    Posts
    5

    Re: Finding data and plotting a scatter chart with VBA

    Thanks for your reply and advice; however, the thing is that this is just a small sample - normally, I would have around 1,000 groups..

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Finding data and plotting a scatter chart with VBA

    I doubt if scatterplot of 1000 series (a) is anything more than just noise, (b) possible in excel - AFAIR 255 is series number limit.

    Provided your data is representative (in a sense that for given series/group there is no x duplicates) you can first make a Pivot table out of your data (groups in row headings, x's in column, or vice versa and Y's in data, then copy/paste as values (pivot table cannot be a source for scatterplot). And now you have your data ready for scatterplot. Of course this can be written as VBA procedure (if you plan to make multiple scatterplots from many different sets of data). but please check my above (b) doubt.
    Last edited by Kaper; 10-04-2017 at 07:22 AM.
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    10-04-2017
    Location
    London, UK
    MS-Off Ver
    2010
    Posts
    5

    Re: Finding data and plotting a scatter chart with VBA

    Ok, I would make several charts and let us say there will be 15 groups in each one of those scatter plot charts.. And, at least once a month, the number of constituents within the group will change, so doing it manually is not an option for me.. =/

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Finding data and plotting a scatter chart with VBA

    How about your sample: is representative (in a sense that for given series/group there is no x duplicates)

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding data and plotting a scatter chart with VBA

    How would you feel about a set of helper columns to the side of your main data table? I would probably do something like this: https://peltiertech.com/conditional-...-excel-charts/ which uses a series of helper columns with a simple IF() function to "conditionally format" the different group types. The most difficult part, if it must be automated, is creating the list of unique group names across the top by formula. If this step does not need to be automated, then it is as easy as entering the group names across the top row. Steps for this approach (if needed):
    1) Enter group names across top row (starting in D1).
    2) Enter IF() formula in D2. =IF(D$1=$A2,$C2,na()) note the mix of relative and absolute references to make copying easy, then copy down and across.
    3a) Select column B and columns D to whatever.
    3b) Insert scatter chart
    3c) Format as desired
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Finding data and plotting a scatter chart with VBA

    Alternatively, I could see using a pivot table for this. As Kaper says, you cannot use a pivot chart, so you have to pay attention to how it is done.
    1) Create pivot table. If you are unfamiliar with pivot tables, start here: http://www.excel-easy.com/data-analy...ot-tables.html
    1a) x axis as row labels
    1b) group as column labels
    1c) sum of y axis as value field. Note at this point that this entire approach will likely fail if it is possible to have two entries for a given group and x axis value. You would need to know before trying this if this is a possibility.
    2) Insert scatter chart. Note that, because a pivot chart cannot be a scatter chart, and a chart based on a pivot table will want to convert itself to a pivot chart, you need to pay careful attention to how you create the chart. I recommend this discussion here: https://peltiertech.com/regular-char...-pivot-tables/ Follow the instructions carefully. It will be a bit tedious to create the first time, but, once it is created, updating should be as simple as editing the raw data and refreshing the pivot table.

  9. #9
    Registered User
    Join Date
    10-04-2017
    Location
    London, UK
    MS-Off Ver
    2010
    Posts
    5

    Re: Finding data and plotting a scatter chart with VBA

    Thanks, I will try to do this you way
    Last edited by desperados2; 10-05-2017 at 09:14 AM.

  10. #10
    Registered User
    Join Date
    10-04-2017
    Location
    London, UK
    MS-Off Ver
    2010
    Posts
    5

    Re: Finding data and plotting a scatter chart with VBA

    Quote Originally Posted by Kaper View Post
    How about your sample: is representative (in a sense that for given series/group there is no x duplicates)
    Not sure what you meant, but will try some of the suggestions below/ above Thanks

  11. #11
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Finding data and plotting a scatter chart with VBA

    I ment:
    is it possible that for given group there will be data like:
    aaa 2 5
    aaa 3 2
    aaa 3 5
    aaa 4 4

    But now try to deal with MrShorty's answer - it also is based on assumption of unique x in given group (see 1c in post #8)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Plotting a circle on a scatter chart
    By Enlighten Me? in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-05-2015, 10:05 AM
  2. Scatter will not use given x-values in plotting data
    By TechCredit in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-12-2014, 02:17 PM
  3. Scatter chart not plotting actual x-values
    By Gumby_Dammit223 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-31-2013, 12:03 PM
  4. Plotting scatter chart with grouped cells
    By dsalter in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-28-2013, 07:44 PM
  5. Plotting XY scatter chart
    By melrosetutu in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-02-2012, 08:01 AM
  6. Help plotting filled shapes (currently plotting outlines using scatter)
    By j_man2211 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-23-2012, 10:34 AM
  7. [SOLVED] scatter chart insists on plotting as a line chart
    By Knows too little in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 03-11-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1