Nm Logo

GPT4 Data Visualization Demo

Version 1.0

This is a transcript of the input and output texts used in a May 2023 demo of prompting GPT-4 to convert prose to data, data to a chart, and then the chart to a text-based conclusion. Watch the screencast for the entire process.

👤 Prompt: Define AI role and goal

You are a lieutenant in a space-faring star navy responsible for compiling planetary surveys from missions to various planets. Your task is to consolidate the results of these reports into a single summary that lists the combined population totals for each alien race. Based on the information in all three surveys, your summary should also infer the value of each civilizations's "peaceful" aspect on a scale from warlike to harmless, and its "sociable" aspect on a scale from secretive to gregarious.

After I type my three planetary surveys, you will write this summary in the form of bullet points.

Type "Understood" if you understand this request.

👤 Source text

Survey 1, from the asteroid Algara:

On this asteroid we visited a Phaestian science outpost consisting of 45 researchers. They greeted us formally and gave us a tour of the facilities. The Phaestians' demeanor was respectful but reserved. Their emotionless expressions made it hard to tell what they were thinking, but we believe they meant us no harm. We also learned of a Hersilian colony on the far side of the asteroid. Our attempt to contact the Hersilians was rebuffed with a warning that their colony was off-limits to outsiders and trespassers would be punished. We estimate the number of Hersilian colonists on Algara to be 100.

Survey 2, from the moon Bezanyi:

Our visit to this moon inhabited by Kaveks received a mixed reception. Once we entered the atmosphere Kaveks fired on our shuttle, forcing us into an emergency landing. We were soon confronted by a band of Kaveks who challenged us to an arm-wrestling contest, threatening to put us to death if we refused. When our beefiest crewmember beat their leader, they invited us to celebrate by joining them in a party, where they toasted our success with mugs of blood wine. After the festivities, they allowed us to return to our ship unscathed once we promised to return for Bezanyi's arm wrestling contest next year. We estimate the moon harbors about 250 Kaveks.

Survey 2, from the planet Czryz:

We found this planet contested by three factions. A magistrate representating a Phaestian city of 1000 colonists politely explained that several of the residents had heard rumors of a secret base of about 450 Hersilians who kept to themselves. While we were speaking, the planet was suddenly attacked from orbit by a Kavek bird of prey, which fired torpedoes indiscriminately at the planet's surface. We hurriedly followed the Phaestians to underground bunker, fearing for our lives. Within minutes a Hersilian warbird decloaked in orbit and fired its disruptors at the attacking vessel. After destroying the Kavek ship, the warbird immediately cloaked again and disappeared without a word to us or the Phaestians. Despite never speaking to the Hersilians, we were grateful for their defense of the planet all the same.

🤖 Response as bullet points

👤 Prompt: Extract data from source text

Now convert your summary to JSON format, including key-value pairs with properties such as total population (as an integer representing the number of colonists); each civilizations's "peaceful" aspect (as an integer on a scale from 1 meaning warlike to 5 meaning harmless); and each civilization's "sociable" aspect (as an integer on a scale from 1 meaning secretive to 5 meaning gregarious).

🤖 Response as JSON


{
  "Phaestians": {
    "total_population": 1045,
    "peaceful_aspect": 5,
    "sociable_aspect": 1
  },
  "Hersilians": {
    "total_population": 550,
    "peaceful_aspect": 3,
    "sociable_aspect": 1
  },
  "Kaveks": {
    "total_population": 250,
    "peaceful_aspect": 1,
    "sociable_aspect": 5
  }
}

👤 Prompt: Draw a chart

Now shift roles to a web developer with expertise in data visualization. Write an HTML document that loads a JavaScript framework such as D3 and includes a custom script that converts this JSON into a multivariate bar chart.

🤖 Response as HTML

Here is an HTML document that loads D3.js and includes a custom script to create a multivariate bar chart using the provided JSON data:



<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Alien Civilization Summary</title>
  <style>
    .bar {
      fill: steelblue;
    }
  </style>
  <script src="https://d3js.org/d3.v6.min.js"></script>
</head>
<body>
  <svg width="800" height="500"></svg>
  <script>
    const data = {
      "Phaestians": {
        "total_population": 1045,
        "peaceful_aspect": 5,
        "sociable_aspect": 1
      },
      "Hersilians": {
        "total_population": 550,
        "peaceful_aspect": 3,
        "sociable_aspect": 1
      },
      "Kaveks": {
        "total_population": 250,
        "peaceful_aspect": 1,
        "sociable_aspect": 5
      }
    };

    const margin = {top: 30, right: 30, bottom: 50, left: 50};
    const width = 800 - margin.left - margin.right;
    const height = 500 - margin.top - margin.bottom;

    const svg = d3.select("svg")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + margin.top + margin.bottom)
      .append("g")
      .attr("transform", `translate(${margin.left},${margin.top})`);

    const x0 = d3.scaleBand()
      .domain(Object.keys(data))
      .range([0, width])
      .padding(0.2);

    const x1 = d3.scaleBand()
      .domain(["total_population", "peaceful_aspect", "sociable_aspect"])
      .range([0, x0.bandwidth()])
      .padding(0.05);

    const y = d3.scaleLinear()
      .domain([0, d3.max(Object.values(data), d => Math.max(d.total_population, d.peaceful_aspect * 250, d.sociable_aspect * 250))])
      .range([height, 0]);

    const xAxis = d3.axisBottom(x0);
    const yAxis = d3.axisLeft(y);

    svg.append("g")
      .attr("class", "x-axis")
      .attr("transform", `translate(0,${height})`)
      .call(xAxis);

    svg.append("g")
      .attr("class", "y-axis")
      .call(yAxis);

    const civilization = svg.selectAll(".civilization")
      .data(Object.entries(data))
      .join("g")
      .attr("class", "civilization")
      .attr("transform", d => `translate(${x0(d[0])},0)`);

    civilization.selectAll(".bar")
      .data(d => Object.entries(d[1]).map(e => ({ key: e[0], value: e[1] })))
      .join("rect")
      .attr("class", "bar")
      .attr("x", d => x1(d.key))
      .attr("y", d => y(d.value))
      .attr("width", x1.bandwidth())
      .attr("height", d => height - y(d.value));
  </script>
</body>
</html>

You can save this code to an HTML file and open

👤 Prompt: Adjust column height

To make the columns closer in height so the bar chart is easier to read, please revise the JSON and JavaScript code above to measure total_population in the hundreds; for example, 1045 will become 10.45.

🤖 Response as revised HTML

Here's the updated HTML document with the JSON data and JavaScript code revised to represent the total_population in hundreds:


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Alien Civilization Summary</title>
  <style>
    .bar {
      fill: steelblue;
    }
  </style>
  <script src="https://d3js.org/d3.v6.min.js"></script>
</head>
<body>
  <svg width="800" height="500"></svg>
  <script>
    const data = {
      "Phaestians": {
        "total_population": 10.45,
        "peaceful_aspect": 5,
        "sociable_aspect": 1
      },
      "Hersilians": {
        "total_population": 5.5,
        "peaceful_aspect": 3,
        "sociable_aspect": 1
      },
      "Kaveks": {
        "total_population": 2.5,
        "peaceful_aspect": 1,
        "sociable_aspect": 5
      }
    };

    const margin = {top: 30, right: 30, bottom: 50, left: 50};
    const width = 800 - margin.left - margin.right;
    const height = 500 - margin.top - margin.bottom;

    const svg = d3.select("svg")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + margin.top + margin.bottom)
      .append("g")
      .attr("transform", `translate(${margin.left},${margin.top})`);

    const x0 = d3.scaleBand()
      .domain(Object.keys(data))
      .range([0, width])
      .padding(0.2);

    const x1 = d3.scaleBand()
      .domain(["total_population", "peaceful_aspect", "sociable_aspect"])
      .range([0, x0.bandwidth()])
      .padding(0.05);

    const y = d3.scaleLinear()
      .domain([0, d3.max(Object.values(data), d => Math.max(d.total_population, d.peaceful_aspect * 2.5, d.sociable_aspect * 2.5))])
      .range([height, 0]);

    const xAxis = d3.axisBottom(x0);
    const yAxis = d3.axisLeft(y);

    svg.append("g")
      .attr("class", "x-axis")
      .attr("transform", `translate(0,${height})`)
      .call(xAxis);

    svg.append("g")
      .attr("class", "y-axis")
      .call(yAxis);

    const civilization = svg.selectAll(".civilization")
      .data(Object.entries(data))
      .join("g")
      .attr("class", "civilization")
      .attr("transform", d => `translate(${x0(d[0])},0)`);

    civilization.selectAll(".bar")
      .data(d => Object.entries(d[1]).map(e => ({ key: e[0], value: e[1] })))
      .join("rect")
      .attr("class", "bar")
      .attr("x", d => x1(d.key))
      .attr("y", d => y(d.value))
      .attr("width", x1.bandwidth())
      .attr("height", d => height - y(d.value));
  </script>
</body>
</html>
You can save this code to an HTML"

👤 Prompt: Adjust chart design

To clarify the properties represented in the chart, please revise the code above to add a custom color for each property (total_population, peaceful_aspect, and sociable_aspect) as well as a chart legend that indicates the properties that correspond to each color. Also add a chart title entitled "Alien Civilization Summary".

🤖 [stops partway through]

👤 [repeats prompt]

Since fulfilling my last request required an answer too long for you to complete, please forget the code you just wrote and instead backtrack to the code you produced for this earlier prompt:

"To make the columns closer in height so the bar chart is easier to read, please revise the JSON and JavaScript code above to measure total_population in the hundreds; for example, 1045 will become 10.45."

Please type "Understood" if you understand this reversion to a previous state of the code, and then I will make my next request.

🤖 Response as revised HTML

To add custom colors for each property, a chart legend, and a chart title to the existing JavaScript code, you can follow the instructions below.

1. Add the following CSS style rules to the `<style>` section in the `<head>` of the HTML document:


.total_population {
  fill: steelblue;
}
.peaceful_aspect {
  fill: orange;
}
.sociable_aspect {
  fill: green;
}

2. Add the chart title to the existing JavaScript code:


svg.append("text")
  .attr("x", width / 2)
  .attr("y", -margin.top / 2)
  .attr("text-anchor", "middle")
  .style("font-size", "20px")
  .style("font-weight", "bold")
  .text("Alien Civilization Summary");

3. Modify the `civilization.selectAll(".bar")` section in the existing JavaScript code to apply the custom colors:


civilization.selectAll(".bar")
  .data(d => Object.entries(d[1]).map(e => ({ key: e[0], value: e[1] })))
  .join("rect")
  .attr("class", d => d.key)
  .attr("x", d => x1(d.key))
  .attr("y", d => y(d.value))
  .attr("width", x1.bandwidth())
  .attr("height", d => height - y(d.value));

4. Add the following code to create the chart legend:


const legendData = [
  { key: 'total_population', label: 'Total Population', color: 'steelblue' },
  { key: 'peaceful_aspect', label: 'Peaceful Aspect', color: 'orange' },
  { key: 'sociable_aspect', label: 'Sociable Aspect', color: 'green' }
];

const legend = svg.append("g")
  .attr("class", "legend")
  .attr("transform", `translate(${width - margin.right}, ${-margin.top})`)
  .selectAll("g")
  .data(legendData)
  .join("g")
  .attr("transform", (d, i) => `translate(0,${i * 20})`);

legend.append("rect")
  .attr("width", 18)
  .attr("height", 18)
  .style("fill", d => d.color);

legend.append("text")
  .attr("x", 24)
  .attr("y", 9)
  .attr("dy", ".35em")
  .text(d => d.label);

Add these excerpts to the corresponding locations in the existing JavaScript code. This will create a multivariate bar chart with custom colors for each property, a chart legend, and a chart title.

👤 Prompt: Adjust chart legend

This is almost perfect, but please change the legend label from "Total Population" to "Population (in hundreds)" and translate the legend to the left so that it doesn't extend beyond the visible boundary of the chart.

🤖 Response as JavaScript

To make the requested changes, modify the `legendData` array and the `translate` attribute of the legend `g` element in the existing JavaScript code.

1. Change the legend label from "Total Population" to "Population (in hundreds)" in the `legendData` array:


const legendData = [
  { key: 'total_population', label: 'Population (in hundreds)', color: 'steelblue' },
  { key: 'peaceful_aspect', label: 'Peaceful Aspect', color: 'orange' },
  { key: 'sociable_aspect', label: 'Sociable Aspect', color: 'green' }
];

2. Adjust the `translate` attribute of the legend `g` element to move the legend to the left:


const legend = svg.append("g")
  .attr("class", "legend")
  .attr("transform", `translate(${width - margin.right - 150}, ${-margin.top})`)
  .selectAll("g")
  .data(legendData)
  .join("g")
  .attr("transform", (d, i) => `translate(0,${i * 20})`);

These changes will update the legend label and reposition the legend so that it doesn't extend beyond the visible boundary of the chart.

👤 Prompt: Draw conclusion based on the chart

Acting once again on behalf of a star navy dedicated to peaceful exploration of the galaxy, decide which alien civilization would make the best ally. Base your recommendation on the information summarized in the chart and JSON. Include potential advantages and disadvantages such as shared knowledge, trade, or security.

🤖 Response as text

Based on the information summarized in the chart and JSON, the Phaestian civilization would make the best ally for a star navy dedicated to peaceful exploration of the galaxy.

Advantages:

1. Peaceful nature: With a peaceful_aspect score of 5, the Phaestians have demonstrated a non-aggressive and non-threatening approach to interactions.

2. Advanced knowledge: The presence of a Phaestian science outpost on Algara suggests that they possess scientific and technological expertise that could be valuable in a partnership focused on exploration and knowledge-sharing.

3. Stability: The Phaestians have established colonies on both Algara and Czryz, which may indicate a level of stability and infrastructure that could be beneficial in trade and diplomatic relations.

Disadvantages:

1. Low sociability: With a sociable_aspect score of 1, the Phaestians may be more reserved and less open to sharing information and forming close relationships.

2. Smaller population: Although their total_population is higher than that of the Hersilians and Kaveks, the Phaestians have a relatively smaller population, which could limit their potential contributions in terms of resources, workforce, and military support.

Despite these disadvantages, the Phaestians' peaceful nature and advanced knowledge make them the most suitable ally for a star navy focused on peaceful exploration. Collaborating with the Phaestians could lead to shared technological advancements, research opportunities, and a strong foundation for peaceful relations across the galaxy.

👤 Prompt: Persuade others to accept your conclusion

Now that you have made your decision, continue your role as lieutenant by writing a persuasive letter inviting the Phaestians to ally with your star navy. Your letter should cite potential advantages of the alliance, but use language and tone that reflects understanding of and empathy for the Phaestian people and culture.

🤖 Response as text

Subject: Invitation for a Galactic Alliance between the Phaestian Civilization and the Star Navy

Esteemed Leaders of the Phaestian Civilization,

We hope this message finds you in good health and high spirits. As representatives of the Star Navy, an organization dedicated to the peaceful exploration and understanding of the galaxy, we would like to extend a sincere invitation for your esteemed civilization to join us in forming a strategic alliance.

Throughout our interactions with various civilizations, we have observed the Phaestians to be a people of great intellect and wisdom. Your commitment to scientific research and technological advancements has not gone unnoticed, and we believe that an alliance between our civilizations would bring about a wealth of shared knowledge and innovation.

We understand that the Phaestian people value discretion and respect for autonomy, and we assure you that our alliance will be built on a foundation of mutual respect and understanding. As allies, we would work together in a way that preserves the unique cultural values and traditions of both parties, while promoting the exchange of ideas and fostering the growth of our civilizations.

By joining forces, our two civilizations would have the opportunity to collaborate on groundbreaking research and expand our understanding of the universe. Together, we can forge a future that is both scientifically prosperous and harmonious, where the spirit of cooperation drives our progress.

Additionally, our alliance would provide a platform for trade and economic growth, benefiting both of our peoples through the exchange of valuable resources and technologies. While maintaining the peaceful nature of our collaboration, we can jointly ensure the security and stability of our respective regions, promoting a sense of unity and mutual protection.

We humbly request your consideration of our proposal and look forward to the possibility of working together for the betterment of both our civilizations and the galaxy as a whole. We are excited to learn from your vast wisdom and expertise and to embark on this journey of exploration, cooperation, and growth together.

Thank you for your time and attention. We eagerly await your response and the opportunity to further discuss the details of this proposed alliance.

With the utmost respect and admiration,

[Your Name]

Lieutenant, Star Navy

👤 Prompt: Write a culturally sensitive announcement

Having informed the Phaestians, now write a conciliatory letter to the Hersilians explaining that you must decline a potential alliance. Your letter may explain the reasons diplomatically, but should use specific language and tone that reflects an understanding of and empathy for the Hersilian people and culture.

🤖 Response as text

Subject: A Message of Gratitude and Understanding to the Hersilian Civilization

Honorable Leaders of the Hersilian Civilization,

We hope this message reaches you in good health and prosperity. As representatives of the Star Navy, an organization devoted to the peaceful exploration and understanding of the galaxy, we would like to express our gratitude for the opportunity to have encountered and learned about your esteemed civilization.

We are writing to inform you that after careful consideration, we have decided to pursue an alliance with the Phaestian civilization. We understand that this decision may come as a disappointment, and we wish to convey our reasons for this choice with utmost respect and understanding.

In our pursuit of a suitable alliance, we have considered various factors such as shared goals and values, as well as the potential for mutual growth and cooperation. While we admire the Hersilian people's strong sense of self-preservation and their dedication to maintaining their independence, we have determined that our strategic objectives align more closely with those of the Phaestians at this time.

We understand the importance of your civilization's privacy and the protection of your territory, and we wish to assure you that we will respect your boundaries and autonomy. As we continue to explore the galaxy, our Star Navy remains committed to fostering peaceful relationships and understanding with civilizations like yours.

While an alliance may not be feasible at this moment, we hope that this decision does not preclude the possibility of future collaboration and exchange between our peoples. We respect and admire the Hersilian culture and hope to maintain a relationship of goodwill and mutual understanding.

We extend our deepest gratitude for your consideration and understanding in this matter. May the Hersilian civilization continue to thrive and prosper in its unique and admirable way.

With the utmost respect,

[Your Name]

Lieutenant, Star Navy

👤 Prompt: Write a different culturally sensitive announcement

Having informed both the Phaestians and Hersilians, now write a conciliatory letter to the Kaveks explaining that you must decline a potential alliance. Your letter may explain the reasons diplomatically, but should use specific language and tone that reflects an understanding of and empathy for the Kavek people and culture.

🤖 Response as text

Subject: A Message of Gratitude and Understanding to the Kavek Civilization

Honorable Leaders of the Kavek Civilization,

We hope this message reaches you in good spirits and strength. As representatives of the Star Navy, an organization dedicated to the peaceful exploration and understanding of the galaxy, we would like to express our gratitude for the opportunity to have encountered and learned about your esteemed civilization.

We are writing to inform you that after careful consideration, we have decided to pursue an alliance with the Phaestian civilization. We understand that this decision may come as a disappointment, and we wish to convey our reasons for this choice with the utmost respect and understanding.

In our pursuit of a suitable alliance, we have considered various factors such as shared goals, values, and the potential for mutual growth and cooperation. While we have come to appreciate the Kavek people's strong sense of tradition, valor, and camaraderie, we have determined that our strategic objectives align more closely with those of the Phaestians at this time.

We acknowledge the Kaveks' prowess in combat and the importance of honor and strength within your culture. We would like to extend our appreciation for the unforgettable experience of participating in your arm-wrestling contest, and we cherish the memory of the shared celebration that followed.

As we continue to explore the galaxy, our Star Navy remains committed to fostering peaceful relationships and understanding with civilizations like yours. We hope that this decision does not preclude the possibility of future collaboration and cultural exchange between our peoples.

We extend our deepest gratitude for your consideration and understanding in this matter. May the Kavek civilization continue to prosper and uphold its proud traditions.

With the utmost respect,

[Your Name]

Lieutenant, Star Navy