135 British towns and cities that gave their name to 394 Royal Navy ships. The bigger the circle, the more ships. Tap a town for its ships, their dates and what is known of their fate.
Somewhere in most British port towns there is a ship's bell, a crest or a plaque from HMS Something, the warship that carried the town's name. Some towns have had one; Gloucester and Newcastle have had nine each. I went through every Royal Navy ship in Wikidata, 6,006 of them, matched their names to British towns and cities, and mapped the result: 394 ships named after 135 places.
The map shows each town as a circle sized by its ships and coloured by when the latest of them served. Tap one to see the list. The essay below explains how the names were matched, why it is harder than it looks, and why the question of what happened to the ships mostly has no answer in the open data.
The 135 towns are spread across all four nations, but heavily English: 112 towns in England, 12 in Scotland, 8 in Wales and 3 in Northern Ireland. More than half (63%) lie within 10 km of the open sea. The most-named are old ports and cathedral cities, and the dockyard towns the Navy lived in: Chatham, Falmouth, Pembroke and Scarborough have seven or eight ships each. 28 towns have had five ships or more; 50 have had just one.

The twenty towns with most ships. Each block is one ship, coloured by when it was commissioned.
Naming ships after towns is old. In the second half of the 1600s about a third of the Royal Navy ships in Wikidata (65 of 195) carried a British town's name: London, Newcastle, Gloucester, York. Many of those names were also the titles of royal dukes and earls, so some of the older ships may honour the duke rather than the town. From the middle of the 1700s town names became rare, lost among a fleet of classical heroes, virtues, animals and battles. They came back in the 20th century with the Town-class cruisers, the wartime Castle-class corvettes, the frigates of the 1950s and 1960s, and the Type 42 destroyers named after cities (14 of them here). The Type 23 frigates of the 1990s (Lancaster, Richmond, St Albans) are named after dukedoms, and are flagged as titles.

Share of Royal Navy ships in Wikidata with a British town's name, by the half century of commissioning (or the class's typical date).
Lancaster has had 4 ships in the data: an HMS Lancaster of 1694, another of 1797, HMS Lancaster Castle, a Castle-class corvette of 1944, and the Type 23 frigate of 1992, named, like its class, after a dukedom (the Duke of Lancaster is the monarch). The Town-class destroyer HMS Lancaster of 1940 is in Wikidata only under its American name, and the Monmouth-class armoured cruiser of 1902 is left out because that class was named after counties. Barrow-in-Furness, which built a good share of the Navy's ships and most of its submarines, has never had a ship of its own name in the data.
The open data is thin here. Only 94 of the 394 ships (24%) have any recorded end in Wikidata, and most of those are just a decommissioning date. 11 are recorded as sunk, wrecked or destroyed, among them HMS Gloucester, sunk off Crete in 1941, and HMS Sheffield and HMS Coventry, lost in the Falklands in 1982. The map can colour towns by these records, but read the colours as gaps in the data as much as facts about the ships.

Recorded fates of the town-named ships in Wikidata.
Wikidata records what a ship is named after for only a fraction of ships, but where it does, the habit is plain in other navies. The United States Navy has the most: 146 ships named after American towns and cities in the data, from Raleigh to Newport News. The Royal Australian Navy names ships after its cities; the Imperial Japanese Navy, by contrast, named ships after mountains, rivers and provinces, almost never towns.

Ships whose Wikidata entry names a town or city they honour (blue) among all ships named after a place, by navy.
I took every ship in Wikidata operated by the Royal Navy with a name beginning HMS. Where Wikidata says what a ship was named after (only 261 ships), I used that, keeping only British towns and cities. For the rest I matched the name exactly to a British town or city in Wikidata (a town, market town, city or seaside resort, or any place of 10,000 people or more), and "Lancaster Castle" style names to their town. I left out ships whose recorded namesake is a person or a foreign place, classes named after other things (fox hunts, racecourses, rivers, flowers), and names that belong to people, battles, rivers or foreign places (Nelson, Wellington, Dunkirk, Gibraltar). Classes named after counties (the County-class cruisers and destroyers) are left out too. 167 of the matches (42%) share their name with a noble title; they are counted but flagged on the map, and without them 227 ships and 93 towns remain. Years are the commissioning year, or for 54 ships the typical year of the ship's class.